|
@@ -26,6 +26,28 @@ const ALI_OSS_BUCKET = process.env.ALI_OSS_BUCKET || "hep-textbook"
|
|
const ALI_OSS_ACCESS_KEY_ID = process.env.ALI_OSS_ACCESS_KEY_ID || "LTAI5t6AbTiAvXmeoVdJZhL3"
|
|
const ALI_OSS_ACCESS_KEY_ID = process.env.ALI_OSS_ACCESS_KEY_ID || "LTAI5t6AbTiAvXmeoVdJZhL3"
|
|
const ALI_OSS_ACCESS_KEY_SECRET = process.env.ALI_OSS_ACCESS_KEY_SECRET || "KLtQRdIW69KLP7jnzHNUf7eKmdptxH"
|
|
const ALI_OSS_ACCESS_KEY_SECRET = process.env.ALI_OSS_ACCESS_KEY_SECRET || "KLtQRdIW69KLP7jnzHNUf7eKmdptxH"
|
|
|
|
|
|
|
|
+const ossClient = new OSS({
|
|
|
|
+
|
|
|
|
+ region: "oss-cn-beijing",
|
|
|
|
+ accessKeyId: ALI_OSS_ACCESS_KEY_ID,
|
|
|
|
+ accessKeySecret: ALI_OSS_ACCESS_KEY_SECRET,
|
|
|
|
+
|
|
|
|
+ bucket: ALI_OSS_BUCKET || "hep-textbook",
|
|
|
|
+ timeout:5000*1000
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+ async function signatureUrl(url,options){
|
|
|
|
+ let expires = options?.expires || 600
|
|
|
|
+ let urlObj = new URL(url)
|
|
|
|
+
|
|
|
|
+ let fileKey = decodeURIComponent(urlObj.pathname)
|
|
|
|
+ let r1 = await ossClient?.signatureUrl(fileKey, {
|
|
|
|
+ expires: expires,
|
|
|
|
+ });
|
|
|
|
+ console.log(r1)
|
|
|
|
+ return r1;
|
|
|
|
+}
|
|
|
|
+
|
|
const bwipjs = require("bwip-js")
|
|
const bwipjs = require("bwip-js")
|
|
export async function toBarCode(text){
|
|
export async function toBarCode(text){
|
|
return new Promise(resolve=>{
|
|
return new Promise(resolve=>{
|
|
@@ -128,6 +150,12 @@ module.exports.createZip = createZip
|
|
|
|
|
|
const download = require('download')
|
|
const download = require('download')
|
|
export async function downloadUrl(url,options) {
|
|
export async function downloadUrl(url,options) {
|
|
|
|
+
|
|
|
|
+ let response = await fetch(url)
|
|
|
|
+ console.log(url)
|
|
|
|
+ if(response?.status==403){
|
|
|
|
+ url = await signatureUrl(url);
|
|
|
|
+ }
|
|
|
|
|
|
if(!fs.existsSync(options?.tempDir)) fs.mkdirSync(options?.tempDir);
|
|
if(!fs.existsSync(options?.tempDir)) fs.mkdirSync(options?.tempDir);
|
|
|
|
|