postcat/upload.js
Scarqin 417e5eeb7f
v0.1.0 (#220)
* v0.1.0

* refactor(unit-test): delete useless unit test file

* fix(mock-edit): xml response body generate error

* refactor(api-test-utils): merge two utils

* refactor(api-form-table): merge query/rest/header to form

* feat: *-member loading UI

* fix: reset password bug

* feat: delete useless code

* fix(select-theme): extension theme title show error after refresh page

* fix: wakeup login modal while get the unlogin status

* feat: delete useless code

* feat: store api

* chore: add remark

* feat: optimize init data

* build: upgrade component reliable

* fix: import xml auto add table row

* fix: update group error

* feat: update group drag

* fix: import lost dataType

* feat: add type when update group

* refactor: get groupList logic

* feat: group fake reload

* perf: install web extension

* fix(extension-detail): author title show error

* feat: update

* feat: ws data

* build: update app package version

* build: update web package version

* fix: ws history view back

* fix: UI

* fix: table-pro-click error

* fix: API view back

* feat: update

* feat: update

* feat: update

* feat: support sort group

* fix: sort bug

* feat: update

* feat: update

* fix: websocket translate

* refactor(api-tab): add type tabViewComponent

* feat: add waitNextTick func

* feat: API update

* refactor: project import

* feat: update

* fix(api-tab): lack of data after refresh page

* refactor: related import/export

* fix: simpleData groupId is hardcode

* fix: query/rest read some bug

* fix: api edit group err

* fix: auto reload groupList when import finish

* fix: ws bug

* feat: add share nav

* feat: export postcatVersion

* feat: API update

* feat: share module

* feat: add pc console tool

* feat: share http model

* feat: API update

* feat: update API

* fix: model error

* fix(api-edit-group): get pure group

* fix: outside apiAttrInfo

* feat: share

* feat: login button/share

* fix: support remote mock

* feat: fix some env bug

* chore: remove compatible code

* style: theme variable table header color

* fix: code editro blank error

* refactor: get role request one time

* feat: test publish

* feat: test build & publish

* feat: update API

* feat: update API

* feat: replace file name

* feat: replace path

* feat: update upload.js

* feat: build

* feat: update version

* feat: update path

* feat: update upload.js

* feat: update

* feat: upload.js

* feat: update

* feat: add linux

* feat: update upload.js

* feat: update

* docs: update

* docs: update

* docs: update

* docs: 1.0.8

* docs: update 0.1.9

* fix: init apiData field type error

* feat: update

* docs: 0.1.11

* docs: 0.1.12

* docs: 0.1.13

* feat: saving btn

* refactor: sync push api

* docs: update 0.1.14

* style: fix setting modal radius

* chore: remove docker:build:web

* chore: remove unuse code

* feat: update

* chore: remove unuse code

* docs: 0.1.16

* docs: 0.1.17

* docs: update

* fix: formdata body show

* feat: download link

* docs: update

* fix: import tips error

* docs: update

* release: v0.1.0

---------

Co-authored-by: kungfuboy <17kungfuboy@gmail.com>
Co-authored-by: buqiyuan <1743369777@qq.com>
2023-02-03 21:03:20 +08:00

94 lines
3.0 KiB
JavaScript

const qiniu = require('qiniu');
const YAML = require('yaml');
const fs = require('fs');
const { AK, SK, bucket } = require('./qiniu_env.js');
const package = require('./package.json');
qiniu.conf.ACCESS_KEY = AK;
qiniu.conf.SECRET_KEY = SK;
// * 构建上传策略函数
const uptoken = (bucket, key) => new qiniu.rs.PutPolicy(bucket + ':' + key).token();
const toLatest = name => name.replace(/\d+\.\d+\.\d+/, 'latest');
const onlyName = name => name.replace(/release\//, '');
// * 构建客户端实例
const client = new qiniu.rs.Client();
// * 上传单个文件
const uploadFile = (token, file, localFile) =>
new Promise(resolve => {
const extra = new qiniu.io.PutExtra();
qiniu.io.putFile(token, file, localFile, extra, err => {
console.log(err ? err : 'success');
return err ? resolve(false) : resolve(true);
});
});
// * 删除单个文件
const removeFile = (spaceName, file) =>
new Promise(resolve => {
client.remove(spaceName, file, (err, ret) => (err ? resolve(false) : resolve(true)));
});
// * 拷贝单个文件
const cpFile = (fromFile, toFile) =>
new Promise(resolve => {
client.copy(bucket, fromFile, bucket, toFile, err => (err ? resolve(false) : resolve(true)));
});
const version = package.version;
const fileList = [
'release/Postcat-Setup-?.exe',
'release/Postcat-?-arm64.dmg',
'release/Postcat-?.dmg',
'release/Postcat-?-mac.zip',
'release/Postcat-?.AppImage',
'release/latest.yml',
'release/latest-linux.yml',
'release/latest-mac.yml'
].map(it => it.replace(/\?/, `${version}`));
// const fileList = ['releass/postcat-Setup-?.png', 'releass/postcat-?.png', 'releass/postcat-?-arm64.png'].map((it) =>
// it.replace(/\?/, `${version}`)
// );
const app = async () => {
const uploadResult = await Promise.all(
fileList.map(async it => {
let isOK;
// * 生成上传 Token
try {
if (it.endsWith('.yml')) {
await removeFile(bucket, `download/${onlyName(it)}`);
const token = uptoken(bucket, `download/${onlyName(it)}`);
isOK = await uploadFile(token, `download/${onlyName(it)}`, it);
} else {
const token = uptoken(bucket, `download/${version}/${it.replace(/release\//, '')}`);
isOK = await uploadFile(token, `download/${version}/${it.replace(/release\//, '')}`, it);
}
} catch (error) {
console.log('error', error);
}
return Promise.resolve(isOK || false);
})
);
console.log('上传结果:', uploadResult);
const deleteResult = await Promise.all(
fileList.map(async it => {
const isOK = await removeFile(bucket, `download/latest/${toLatest(onlyName(it))}`);
Promise.resolve(isOK || false);
})
);
console.log('删除结果:', deleteResult);
const copyResult = await Promise.all(
fileList.map(async it => {
const isOK = await cpFile(`download/${version}/${onlyName(it)}`, `download/latest/${toLatest(onlyName(it))}`);
Promise.resolve(isOK || false);
})
);
console.log('拷贝结果', copyResult);
};
app();