feat: update file api

This commit is contained in:
yanglbme 2020-12-02 11:49:00 +08:00
parent 2648c03b97
commit 36dfd1ae02
3 changed files with 11 additions and 12 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "vue-md", "name": "vue-md",
"version": "1.4.6", "version": "1.4.7",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "vue-md", "name": "vue-md",
"version": "1.4.6", "version": "1.4.7",
"homepage": ".", "homepage": ".",
"description": "An open-source wechat markdown editor.", "description": "An open-source wechat markdown editor.",
"author": "doocs", "author": "doocs",

View File

@ -161,7 +161,6 @@ async function aliOSSFileUpload(content, filename) {
path, path,
} = JSON.parse(localStorage.getItem("aliOSSConfig")); } = JSON.parse(localStorage.getItem("aliOSSConfig"));
const buffer = Buffer(content, "base64"); const buffer = Buffer(content, "base64");
try {
const dir = `${path}/${dateFilename}`; const dir = `${path}/${dateFilename}`;
const client = new OSS({ const client = new OSS({
region, region,
@ -169,10 +168,10 @@ async function aliOSSFileUpload(content, filename) {
accessKeyId, accessKeyId,
accessKeySecret, accessKeySecret,
}); });
try {
const res = await client.put(dir, buffer); const res = await client.put(dir, buffer);
return cdnHost == "" if (cdnHost == "") return res.url;
? res.url return `${cdnHost}/${path == "" ? dateFilename : dir}`;
: `${cdnHost}/${path == "" ? dateFilename : dir}`;
} catch (e) { } catch (e) {
return Promise.reject(e); return Promise.reject(e);
} }