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

@@ -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,