4.1 同步发版内容到天梯
This commit is contained in:
@ -1,27 +1,191 @@
|
||||
/*
|
||||
* @Author: liqiang
|
||||
* @Date: 2020-12-14 10:13:59
|
||||
* @LastEditTime: 2021-03-09 18:16:03
|
||||
* @LastEditors: Please set LastEditors
|
||||
* @Description: In User Settings Edit
|
||||
* @FilePath: \ebtp-cloud-frontend\src\utils\DownloadUtils.ts
|
||||
* @Author: zhoujianlong
|
||||
* @Date: 2022-03-03 09:06:36
|
||||
* @Last Modified by: zhoujianlong
|
||||
* @Last Modified time: 2022-03-17 16:40:43
|
||||
*/
|
||||
|
||||
import { getUserToken } from "./session";
|
||||
import { getDownloadSecretKey, getFilelist, getFilelistBySecond } from "@/services/download_";
|
||||
import { isEmpty, isNotEmpty } from "./CommonUtils";
|
||||
|
||||
/**
|
||||
* 下载接口路径(bid)
|
||||
* 文件上传
|
||||
*/
|
||||
export const downloadAttachmentPath = '/api/core-service-ebtp-updownload/v1/attachment/download/bid/';
|
||||
export const uploadAttachmentPath = '/api/doc/v1.0/files/upload';
|
||||
/**
|
||||
* 下载接口路径(oid)
|
||||
* 获取密钥
|
||||
*/
|
||||
export const downloadAttachmentPathOId = '/api/core-service-ebtp-updownload/v1/attachment/download/oid/';
|
||||
export const downloadSecretKeyPath = '/api/doc/api/data-service-document-center/outer/v1.0/files/getSecretKey';
|
||||
/**
|
||||
* 文件下载(必须有密钥)
|
||||
*/
|
||||
export const downloadAttachmentPath = '/api/doc/api/data-service-document-center/outer/v1.0/files/getDownload';
|
||||
/**
|
||||
* 获取雪花id
|
||||
*/
|
||||
export const getSnowIdPath = '/api/core-service-ebtp-updownload/v1/business/id';
|
||||
/**
|
||||
* 文件物理删除
|
||||
*/
|
||||
export const removeFilePath = '/api/doc/v1.0/files/disk';
|
||||
/**
|
||||
* 查询文件列表(根据objectId)
|
||||
*/
|
||||
export const findFilelistPath = '/api/doc/v1.0/files/queryReturn';
|
||||
/**
|
||||
* 图片展示
|
||||
*/
|
||||
export const pictureDisplayPath = '/api/doc/v1.0/files/display';
|
||||
/**
|
||||
* 文件下载(不用文件流)
|
||||
*/
|
||||
export const downloadPath = '/api/doc/v1.0/files/download';
|
||||
/**
|
||||
* 查询文件列表(根据2.0 bid)
|
||||
*/
|
||||
export const findFilelistPathBySecond = 'http://111.198.162.67:8081/downloadfile/v1/file/getFileListById';
|
||||
/**
|
||||
* 文件下载(根据2.0 bid fileId)
|
||||
*/
|
||||
export const downloadPathBySecond = 'http://111.198.162.67:8081/downloadfile/v1/file/downloadFileStreamById';
|
||||
|
||||
const authorization = '?Authorization';
|
||||
export interface FilelistProps {
|
||||
uid: string,
|
||||
name: string,
|
||||
status: 'uploading' | 'done' | 'error' | 'removed',
|
||||
url: string,
|
||||
}
|
||||
/**
|
||||
* 获取下载token
|
||||
* 校验3.0 ObjectId
|
||||
* @param objectId
|
||||
* @returns
|
||||
*/
|
||||
export function getDownloadToken () {
|
||||
return authorization + '=' + getUserToken();
|
||||
const checkObjectId = (objectId: string) => {
|
||||
const pattern = /[a-zA-Z]+/;
|
||||
return objectId.length == 19 && !pattern.test(objectId);
|
||||
}
|
||||
/**
|
||||
* 取当前时间时间戳(加密)
|
||||
* @returns
|
||||
*/
|
||||
const getTimeStamp = () => {
|
||||
const cipherMode = '1';
|
||||
const publicKey = '045631900E382D3DA75BD3E977CD6B28556DA3DF15820945F9BFB69E0F7456DF22D4EAB9CCD45B3B4959B85CEB4A2C4BB03AB5E4C08BA6A79E5B7C6AB63C20D932';
|
||||
const sm2 = require('sm-crypto').sm2;
|
||||
const date = Math.round(new Date().getTime() / 1000);
|
||||
return '04' + sm2.doEncrypt(date, publicKey, cipherMode);
|
||||
}
|
||||
/**
|
||||
* 文件下载
|
||||
* @param {fileId} uid
|
||||
*/
|
||||
export const downloadFile = async ({ uid, name }: any) => {
|
||||
if (isNotEmpty(uid)) {
|
||||
if (checkObjectId(uid)) {//判断3.0 fileId
|
||||
const keyRes = await getDownloadSecretKey({ fileId: uid });//获取key
|
||||
keyRes?.success && (window.location.href = downloadAttachmentPath + '?fileId=' + uid + '&documentSecretKey=' + keyRes?.data);
|
||||
} else {
|
||||
window.location.href = downloadPathBySecond + '?id=' + uid + '&p=' + getTimeStamp();
|
||||
}
|
||||
// keyRes?.success && window.fetch(downloadAttachmentPath + '?fileId=' + uid + '&documentSecretKey=' + keyRes?.data, {
|
||||
// method: "GET",
|
||||
// headers: {
|
||||
// Authorization: getUserToken(),
|
||||
// currentRoleCode: getSessionRoleData()?.roleCode,
|
||||
// },
|
||||
// credentials: 'include',
|
||||
// }).then((response) => {
|
||||
// // 这里才是下载附件逻辑处理的地方
|
||||
// response.blob().then(blob => {
|
||||
// const blobUrl = window.URL.createObjectURL(blob);
|
||||
// const aElement = document.createElement("a");
|
||||
// aElement.href = blobUrl; // 设置a标签路径
|
||||
// aElement.download = name;
|
||||
// aElement.click();
|
||||
// window.URL.revokeObjectURL(blobUrl);
|
||||
// });
|
||||
// });
|
||||
}
|
||||
}
|
||||
/**
|
||||
* objectId文件下载(只含一个文件)
|
||||
* @param {业务Id} objectId
|
||||
*/
|
||||
export const downloadFileObjectId = (objectId: string) => {
|
||||
if (isNotEmpty(objectId)) {
|
||||
if (checkObjectId(objectId)) {//判断3.0 objectId
|
||||
getFilelist([objectId]).then(res => {
|
||||
if (res?.success && res?.data?.length > 0) {
|
||||
downloadFile({ uid: res?.data[res?.data?.length - 1].fileId });
|
||||
}
|
||||
})
|
||||
} else {
|
||||
window.location.href = downloadPathBySecond + '?id=' + objectId + '&p=' + getTimeStamp();
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* objectId获取文件下载链接(只含一个文件)
|
||||
* @param {业务Id} objectId
|
||||
* @returns
|
||||
*/
|
||||
export const getDownloadFileUrl = async (objectId: string) => {
|
||||
let url = null;
|
||||
if (isNotEmpty(objectId)) {
|
||||
if (checkObjectId(objectId)) {//判断3.0 objectId
|
||||
await getFilelist([objectId]).then(async res => {
|
||||
if (res?.success && res?.data?.length > 0) {
|
||||
const keyRes = await getDownloadSecretKey({ fileId: res?.data[res?.data?.length - 1].fileId });//获取key
|
||||
url = downloadAttachmentPath + '?fileId=' + res?.data[res?.data?.length - 1].fileId + '&documentSecretKey=' + keyRes?.data
|
||||
}
|
||||
})
|
||||
} else {
|
||||
url = downloadPathBySecond + '?id=' + objectId + '&p=' + getTimeStamp();
|
||||
}
|
||||
|
||||
}
|
||||
return url;
|
||||
}
|
||||
/**
|
||||
* 获取文件列表
|
||||
* @param objectId
|
||||
* @returns
|
||||
*/
|
||||
export async function getFileListByBid(objectId: string) {
|
||||
let result: FilelistProps[] = [];
|
||||
if (isEmpty(objectId)) {
|
||||
return [];
|
||||
}
|
||||
if (checkObjectId(objectId)) {//判断3.0 objectId
|
||||
return getFilelist([objectId]).then(res => {
|
||||
if (res?.success && res?.data?.length > 0) {
|
||||
res?.data?.forEach(({ fileId, originalName }: any) => {
|
||||
result.push({
|
||||
uid: fileId,
|
||||
name: originalName,
|
||||
status: 'done',
|
||||
url: 'javascript:void(0);',
|
||||
})
|
||||
});
|
||||
return result;
|
||||
}
|
||||
return [];
|
||||
})
|
||||
} else {
|
||||
return getFilelistBySecond(objectId, getTimeStamp()).then(response => response.json()).then(res => {
|
||||
if (res?.length > 0) {
|
||||
res?.forEach(({ id, bid, filename }: any) => {
|
||||
result.push({
|
||||
uid: id,
|
||||
name: filename,
|
||||
status: 'done',
|
||||
url: 'javascript:void(0);',
|
||||
})
|
||||
});
|
||||
return result;
|
||||
}
|
||||
return [];
|
||||
})
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user