mirror of
https://github.com/doocs/md.git
synced 2024-11-28 13:36:32 +08:00
feat: update cdnHost
This commit is contained in:
parent
9848a76c84
commit
b344d67351
@ -5,6 +5,7 @@ import Buffer from 'buffer-from';
|
|||||||
import {
|
import {
|
||||||
v4 as uuidv4
|
v4 as uuidv4
|
||||||
} from 'uuid';
|
} from 'uuid';
|
||||||
|
import { resolveConfigFile } from 'prettier';
|
||||||
|
|
||||||
const defaultConfig = {
|
const defaultConfig = {
|
||||||
username: 'filess',
|
username: 'filess',
|
||||||
@ -29,7 +30,7 @@ function fileUpload(content, file) {
|
|||||||
case 'aliOSS':
|
case 'aliOSS':
|
||||||
return aliOSSFileUpload(content, file.name);
|
return aliOSSFileUpload(content, file.name);
|
||||||
case 'txCOS':
|
case 'txCOS':
|
||||||
return txCOSFileUpload(file);
|
return txCOSFileUpload(file);
|
||||||
case 'github':
|
case 'github':
|
||||||
default:
|
default:
|
||||||
return ghFileUpload(content, file.name);
|
return ghFileUpload(content, file.name);
|
||||||
@ -79,7 +80,7 @@ async function ghFileUpload(content, filename) {
|
|||||||
const githubResourceUrl = 'raw.githubusercontent.com/filess/images/master/';
|
const githubResourceUrl = 'raw.githubusercontent.com/filess/images/master/';
|
||||||
const cdnResourceUrl = 'cdn.jsdelivr.net/gh/filess/images/';
|
const cdnResourceUrl = 'cdn.jsdelivr.net/gh/filess/images/';
|
||||||
return isDefault ? res.content.download_url.replace(githubResourceUrl, cdnResourceUrl) : res.content.download_url;
|
return isDefault ? res.content.download_url.replace(githubResourceUrl, cdnResourceUrl) : res.content.download_url;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function aliOSSFileUpload(content, filename) {
|
async function aliOSSFileUpload(content, filename) {
|
||||||
@ -95,10 +96,7 @@ async function aliOSSFileUpload(content, filename) {
|
|||||||
accessKeySecret: aliOSSConfig.accessKeySecret
|
accessKeySecret: aliOSSConfig.accessKeySecret
|
||||||
});
|
});
|
||||||
const res = await client.put(dir, buffer);
|
const res = await client.put(dir, buffer);
|
||||||
if(aliOSSConfig.cdnHost != ''){
|
return aliOSSConfig.cdnHost == '' ? res.url : aliOSSConfig.cdnHost + '/' + (aliOSSConfig.path == '' ? dateFilename : dir);
|
||||||
return aliOSSConfig.cdnHost +'/'+dir;
|
|
||||||
}
|
|
||||||
return res.url;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return Promise.reject(e);
|
return Promise.reject(e);
|
||||||
}
|
}
|
||||||
@ -117,16 +115,15 @@ async function txCOSFileUpload(file) {
|
|||||||
Region: txCOSConfig.region,
|
Region: txCOSConfig.region,
|
||||||
Key: txCOSConfig.path + '/' + dateFilename,
|
Key: txCOSConfig.path + '/' + dateFilename,
|
||||||
Body: file
|
Body: file
|
||||||
}, function(err, data) {
|
}, function (err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
|
} else if (txCOSConfig.cdnHost) {
|
||||||
|
// if cdnHost exists
|
||||||
|
resolve(txCOSConfig.path != '' ? txCOSConfig.cdnHost + '/' + txCOSConfig.path + '/' + dateFilename : txCOSConfig.cdnHost + '/' + dateFilename);
|
||||||
} else {
|
} else {
|
||||||
if(txCOSConfig.cdnHost != ''){
|
// if cdnHost not exists
|
||||||
resolve(txCOSConfig.cdnHost+'/'+txCOSConfig.path + '/' + dateFilename);
|
reject(data.Location);
|
||||||
}else{
|
|
||||||
resolve(data.Location);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -86,7 +86,7 @@
|
|||||||
<el-input v-model.trim="formTxCOS.region"
|
<el-input v-model.trim="formTxCOS.region"
|
||||||
placeholder="如:ap-guangzhou"></el-input>
|
placeholder="如:ap-guangzhou"></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="自定义CDN域名" :required="false">
|
<el-form-item label="自定义 CDN 域名" :required="false">
|
||||||
<el-input v-model.trim="formTxCOS.cdnHost"
|
<el-input v-model.trim="formTxCOS.cdnHost"
|
||||||
placeholder="如:https://imagecdn.alidaodao.com"></el-input>
|
placeholder="如:https://imagecdn.alidaodao.com"></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
@ -131,7 +131,7 @@ export default {
|
|||||||
bucket: "",
|
bucket: "",
|
||||||
region: "",
|
region: "",
|
||||||
path: "",
|
path: "",
|
||||||
cdnHost:""
|
cdnHost: "",
|
||||||
},
|
},
|
||||||
formTxCOS: {
|
formTxCOS: {
|
||||||
secretId: "",
|
secretId: "",
|
||||||
@ -139,7 +139,7 @@ export default {
|
|||||||
bucket: "",
|
bucket: "",
|
||||||
region: "",
|
region: "",
|
||||||
path: "",
|
path: "",
|
||||||
cdnHost:""
|
cdnHost: "",
|
||||||
},
|
},
|
||||||
options: [{
|
options: [{
|
||||||
value: "default",
|
value: "default",
|
||||||
|
Loading…
Reference in New Issue
Block a user