extrafile

This commit is contained in:
Wang Kejun 2022-05-31 19:38:26 +08:00
parent 744be645ec
commit 55ee09b413
7 changed files with 44 additions and 12 deletions

View File

@ -8,6 +8,7 @@ export declare type SystemConfig = {
uploadHost: string;
bucket: string;
domain: string;
protocol: string | string[];
};
};
Map?: {

View File

@ -1,3 +1,4 @@
import { OpSchema as ExtraFile } from 'oak-app-domain/ExtraFile/Schema';
export declare function composeFileUrl(extraFile: Pick<ExtraFile, 'type' | 'bucket' | 'filename' | 'origin' | 'extra1' | 'objectId' | 'extension' | 'entity'>): string;
import { SystemConfig } from 'oak-app-domain/System/Schema';
export declare function composeFileUrl(extraFile: Pick<ExtraFile, 'type' | 'bucket' | 'filename' | 'origin' | 'extra1' | 'objectId' | 'extension' | 'entity'>, systemConfig?: SystemConfig): string;
export declare function decomposeFileUrl(url: string): Pick<ExtraFile, 'bucket' | 'filename' | 'origin' | 'type' | 'extra1'>;

View File

@ -1,14 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decomposeFileUrl = exports.composeFileUrl = void 0;
function composeFileUrl(extraFile) {
function composeFileUrl(extraFile, systemConfig) {
const { type, bucket, filename, origin, extra1, objectId, extension, entity } = extraFile;
console.log(extraFile);
if (extra1) {
// 有extra1就用extra1
return extra1;
}
// 缺少https和域名
return `${entity}/${objectId}.${extension}`;
if (systemConfig && systemConfig.Cos) {
const { domain, protocol } = systemConfig.Cos[origin];
let protocol2 = protocol;
if (protocol instanceof Array) {
// protocol存在https 说明域名有证书
const index = protocol.includes('https')
? protocol.findIndex((ele) => ele === 'https')
: 0;
protocol2 = protocol[index];
}
return `${protocol2}://${domain}/${entity}/${objectId}.${extension}`;
}
return '';
}
exports.composeFileUrl = composeFileUrl;
function decomposeFileUrl(url) {

View File

@ -8,7 +8,8 @@ export type SystemConfig = {
secretKey: string;
uploadHost: string; //七牛上传域名
bucket: string;
domain: string;
domain: string; //域名
protocol: string | string[];
};
};
Map?: {

View File

@ -1,4 +1,5 @@
import { OpSchema as ExtraFile } from 'oak-app-domain/ExtraFile/Schema';
import { SystemConfig } from 'oak-app-domain/System/Schema';
export function composeFileUrl(
extraFile: Pick<
@ -11,16 +12,30 @@ export function composeFileUrl(
| 'objectId'
| 'extension'
| 'entity'
>
>,
systemConfig?: SystemConfig
) {
const { type, bucket, filename, origin, extra1, objectId, extension, entity } =
extraFile;
console.log(extraFile);
if (extra1) {
// 有extra1就用extra1
return extra1!;
return extra1;
}
// 缺少https和域名
return `${entity}/${objectId}.${extension}`;
if (systemConfig && systemConfig.Cos) {
const { domain, protocol } =
systemConfig.Cos[origin as keyof typeof systemConfig.Cos]!;
let protocol2 = protocol;
if (protocol instanceof Array) {
// protocol存在https 说明域名有证书
const index = (protocol as ['http', 'https']).includes('https')
? protocol.findIndex((ele) => ele === 'https')
: 0;
protocol2 = protocol[index];
}
return `${protocol2}://${domain}/${entity}/${objectId}.${extension}`;
}
return '';
}
export function decomposeFileUrl(url: string): Pick<ExtraFile, 'bucket' | 'filename' | 'origin' | 'type' | 'extra1'> {

View File

@ -4,10 +4,12 @@ OakComponent(
{
entity: 'extraFile',
isList: false,
formData: async ({ data: extraFile }) => {
formData: async ({ data: extraFile, features }) => {
const application = features.application.getApplication();
const isTmp = extraFile?.id && isMockId(extraFile.id);
return {
src: extraFile && composeFileUrl(extraFile),
src: extraFile && composeFileUrl(extraFile, application?.system?.config),
isTmp,
};
},

View File

@ -160,7 +160,7 @@ OakComponent({
);
Object.assign(updateData, {
bucket,
extra1: url,
extra1: null,
});
},
};