fix: remove expired token

This commit is contained in:
yanglbme 2020-08-29 14:42:02 +08:00
parent 46f2b867a0
commit 7e333ed54c
3 changed files with 15 additions and 14 deletions

View File

@ -3,13 +3,15 @@ import { v4 as uuidv4 } from 'uuid';
const fileUploadConfig = { const fileUploadConfig = {
username: 'filess', username: 'filess',
repo: 'images', repo: 'images',
access_tokens: [ accessToken: [
'cc16734fc2d92c5b6d90155f0da9b5c43701b386', '7715d7ca67b5d3837cfdoocsmde8c38421815aa423510af',
'f5c1b69cac9e2d53213adb1adda927ae7b3ca762', 'c411415bf95dbe39625doocsmd5047ba9b7a2a6c9642abe',
'5533628a92d69d2271d6d1fdd5a9170c7de65bc8', '2821cd8819fa345c053doocsmdca86ac653f8bc20db1f1b',
'7dc129821137b52d9fb897ba4a96d16224b63845', '445f0dae46ef1f2a4d6doocsmdc797301e94797b4750a4c',
'90669202e6277399ec0ea81649953b8f60793c6a', 'cc1d0c1426d0fd0902bdoocsmdd2d7184b14da61b86ec46',
'a1900917f80c8c1b2ad73327e7c35b47106025dd' 'b67e9d15cb6f910492fdoocsmdac6b44d379c953bb19eff',
'618c4dc2244ccbbc088doocsmd125d17fd31b7d06a50cf3',
'a4b581732e1c1507458doocsmdc5b223b27dae5e2e16a55'
] ]
} }
@ -18,9 +20,9 @@ function fileUpload(content, fileName) {
const date = new Date(); const date = new Date();
const dir = date.getFullYear() + '/' + (date.getMonth() + 1) + '/' + date.getDate(); const dir = date.getFullYear() + '/' + (date.getMonth() + 1) + '/' + date.getDate();
const uuid = uuidv4(); const uuid = uuidv4();
const token = fileUploadConfig.access_tokens[Math.round(fileUploadConfig.access_tokens.length * Math.random())]; const token = fileUploadConfig.accessToken[Math.floor(Math.random() * fileUploadConfig.accessToken.length)].replace('doocsmd', '');
const dateFilename = new Date().getTime() + '-' + uuid + '.' + fileName.split('.')[1]; const dateFilename = new Date().getTime() + '-' + uuid + '.' + fileName.split('.')[1];
const url = `https://api.github.com/repos/${fileUploadConfig.username}/${fileUploadConfig.repo}/contents/${dir}/${dateFilename}?access_token=${token}`; const url = `https://api.github.com/repos/${fileUploadConfig.username}/${fileUploadConfig.repo}/contents/${dir}/${dateFilename}`;
return fetch({ return fetch({
url, url,
@ -29,7 +31,7 @@ function fileUpload(content, fileName) {
'Authorization': 'token ' + token 'Authorization': 'token ' + token
}, },
data: { data: {
message: 'Upload image by https://github.com/doocs/md', message: 'Upload image by https://doocs.github.io/md',
content: content content: content
} }
}) })

View File

@ -14,9 +14,8 @@ export function uploadImgFile(file) {
imgFile.readAsDataURL(file); imgFile.readAsDataURL(file);
imgFile.onload = function() { imgFile.onload = function() {
const base64Cotent = this.result.split(',').pop(); const base64Content = this.result.split(',').pop();
fileApi.fileUpload(base64Content, file.name).then(res=> {
fileApi.fileUpload(base64Cotent, file.name).then(res=> {
const imageUrl = res.content.download_url.replace(githubResourceUrl, cdnResourceUrl) const imageUrl = res.content.download_url.replace(githubResourceUrl, cdnResourceUrl)
resolve(imageUrl); resolve(imageUrl);

View File

@ -1,7 +1,7 @@
<template> <template>
<el-container class="top is-dark"> <el-container class="top is-dark">
<!-- 图片上传 --> <!-- 图片上传 -->
<el-upload class="header__item" action="https://imgkr.com/api/files/upload" <el-upload class="header__item" action="https://github.com/doocs/md"
:headers="{'Content-Type': 'multipart/form-data'}" :headers="{'Content-Type': 'multipart/form-data'}"
:show-file-list="false" :multiple="true" accept=".jpg,.jpeg,.png,.gif" name="file" :show-file-list="false" :multiple="true" accept=".jpg,.jpeg,.png,.gif" name="file"
:before-upload="beforeUpload"> :before-upload="beforeUpload">