md/src/api/file.js

34 lines
709 B
JavaScript
Raw Normal View History

2020-05-01 21:30:25 +08:00
import fetch from './fetch';
2020-09-07 23:06:43 +08:00
import store from '../store/index';
2020-08-31 20:48:22 +08:00
import {
v4 as uuidv4
} from 'uuid';
function fileUpload(content, filename) {
2020-09-07 23:06:43 +08:00
const {
method,
token,
url
} = store.getters['imageApi/config'];
2020-08-31 20:48:22 +08:00
const uuid = uuidv4();
const dateFilename = new Date().getTime() + '-' + uuid + '.' + filename.split('.')[1];
2020-09-07 23:06:43 +08:00
const uploadUrl = url + dateFilename;
2020-05-01 21:30:25 +08:00
return fetch({
2020-09-07 23:06:43 +08:00
url: uploadUrl,
method,
2020-08-29 11:55:16 +08:00
headers: {
'Authorization': 'token ' + token
},
data: {
2020-08-29 14:42:02 +08:00
message: 'Upload image by https://doocs.github.io/md',
2020-08-29 11:55:16 +08:00
content: content
}
2020-05-01 21:30:25 +08:00
})
}
export default {
fileUpload
2020-08-31 20:48:22 +08:00
};