Updated: filename & file extname with qiniu & weibo

This commit is contained in:
Molunerfinn 2018-03-08 16:50:56 +08:00
parent 504690b729
commit df39511cdf
5 changed files with 17 additions and 6 deletions

View File

@ -73,6 +73,7 @@
"dependencies": {
"axios": "^0.16.1",
"element-ui": "^2.0.5",
"fecha": "^2.3.3",
"fs-extra": "^4.0.2",
"image-size": "^0.6.1",
"keycode": "^2.1.9",

View File

@ -1,6 +1,7 @@
import fs from 'fs-extra'
import path from 'path'
import sizeOf from 'image-size'
import fecha from 'fecha'
const imgFromPath = async (imgPath) => {
let results = []
@ -13,7 +14,8 @@ const imgFromPath = async (imgPath) => {
base64Image,
fileName,
width: imgSize.width,
height: imgSize.height
height: imgSize.height,
extname: path.extname(item.name)
})
}))
return results
@ -22,12 +24,13 @@ const imgFromPath = async (imgPath) => {
const imgFromClipboard = (file) => {
let result = []
if (file !== null) {
const today = new Date().toLocaleString().replace(/[ ]+/g, '-').replace(/\/+/g, '-')
const today = fecha.format(new Date(), 'YYYYMMDDHHmmss')
result.push({
base64Image: file.imgUrl.replace(/^data\S+,/, ''),
fileName: `${today}.png`,
width: file.width,
height: file.height
height: file.height,
extname: '.png'
})
}
return result
@ -44,7 +47,8 @@ const imgFromUploader = async (files) => {
base64Image,
fileName,
width: imgSize.width,
height: imgSize.height
height: imgSize.height,
extname: path.extname(item.name)
})
}))
return results

View File

@ -67,9 +67,11 @@ const weiboUpload = async function (img, type, webContents) {
})
notification.show()
} else {
imgList[i]['imgUrl'] = `https://ws1.sinaimg.cn/${quality}/${resTextJson.data.pics.pic_1.pid}`
const extname = imgList[i].extname === '.gif' ? '.gif' : '.jpg'
imgList[i]['imgUrl'] = `https://ws1.sinaimg.cn/${quality}/${resTextJson.data.pics.pic_1.pid}${extname}`
imgList[i]['type'] = 'weibo'
}
delete imgList[i].extname
}
webContents.send('uploadProgress', 100)
return imgList

View File

@ -98,7 +98,7 @@ export default {
name: 'setting-page',
data () {
return {
version: pkg.version,
version: process.env.NODE_ENV === 'production' ? pkg.version : 'Dev',
defaultActive: 'upload',
menu: null,
visible: false,

View File

@ -3556,6 +3556,10 @@ fd-slicer@~1.0.1:
dependencies:
pend "~1.2.0"
fecha@^2.3.3:
version "2.3.3"
resolved "http://registry.npm.taobao.org/fecha/download/fecha-2.3.3.tgz#948e74157df1a32fd1b12c3a3c3cdcb6ec9d96cd"
figures@^1.4.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/figures/-/figures-1.7.0.tgz#cbe1e3affcf1cd44b80cadfed28dc793a9701d2e"