批量导入
This commit is contained in:
parent
4eb2554c20
commit
abbf6d9556
@ -193,10 +193,6 @@ const RESOURCE_NAME_TRANSLATION_ENTRIES = ([
|
|||||||
(current, next) => next[0].length - current[0].length,
|
(current, next) => next[0].length - current[0].length,
|
||||||
);
|
);
|
||||||
|
|
||||||
function isImageSourceTypeByType(type: string) {
|
|
||||||
return ['CHAT_BUBBLE', 'LAYOUT', 'THEME'].includes(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isAmountRequiredByType(type: string) {
|
function isAmountRequiredByType(type: string) {
|
||||||
return !['CUSTOMIZE', 'FRAGMENTS'].includes(type);
|
return !['CUSTOMIZE', 'FRAGMENTS'].includes(type);
|
||||||
}
|
}
|
||||||
@ -209,7 +205,6 @@ function showExpandUploadByType(type: string) {
|
|||||||
return type === 'CHAT_BUBBLE';
|
return type === 'CHAT_BUBBLE';
|
||||||
}
|
}
|
||||||
|
|
||||||
const isImageSourceType = computed(() => isImageSourceTypeByType(batchForm.type));
|
|
||||||
const isAmountRequired = computed(() => isAmountRequiredByType(batchForm.type));
|
const isAmountRequired = computed(() => isAmountRequiredByType(batchForm.type));
|
||||||
const showExpandUpload = computed(() => showExpandUploadByType(batchForm.type));
|
const showExpandUpload = computed(() => showExpandUploadByType(batchForm.type));
|
||||||
const hasExpandColumn = computed(
|
const hasExpandColumn = computed(
|
||||||
@ -416,43 +411,6 @@ function isResourceFile(file: File) {
|
|||||||
return /\.(mp4|pag|svga|zip)$/i.test(file.name);
|
return /\.(mp4|pag|svga|zip)$/i.test(file.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
function classifyFile(file: File): AssetKind | null {
|
|
||||||
const path = getFilePath(file);
|
|
||||||
const lowerPath = path.toLowerCase();
|
|
||||||
const image = isImageFile(file);
|
|
||||||
if (!image && !isResourceFile(file)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
image
|
|
||||||
&& showExpandUpload.value
|
|
||||||
&& /(^|\/)(android|expand)(\/|$)|[_-](android|expand)\./i.test(lowerPath)
|
|
||||||
) {
|
|
||||||
return 'expand';
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
image
|
|
||||||
&& /(^|\/)(cover|covers|封面)(\/|$)|[_-](cover|封面)\./i.test(lowerPath)
|
|
||||||
) {
|
|
||||||
return 'cover';
|
|
||||||
}
|
|
||||||
if (isResourceFile(file)) {
|
|
||||||
return 'source';
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
image
|
|
||||||
&& isImageSourceType.value
|
|
||||||
&& /(^|\/)(source|resource|resources|ios|资源)(\/|$)|[_-](source|resource|ios|资源)\./i.test(lowerPath)
|
|
||||||
) {
|
|
||||||
return 'source';
|
|
||||||
}
|
|
||||||
return image ? 'cover' : 'source';
|
|
||||||
}
|
|
||||||
|
|
||||||
function getFileBaseName(file: File) {
|
|
||||||
return normalizeBaseName(getPathFileName(getFilePath(file)));
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseStructuredResourceFile(file: File): null | StructuredResourceFile {
|
function parseStructuredResourceFile(file: File): null | StructuredResourceFile {
|
||||||
if (!isImageFile(file) && !isResourceFile(file)) {
|
if (!isImageFile(file) && !isResourceFile(file)) {
|
||||||
return null;
|
return null;
|
||||||
@ -489,8 +447,9 @@ function parseStructuredResourceFile(file: File): null | StructuredResourceFile
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const amount = Number(parts[parts.length - 3]);
|
const amount = Number(parts[parts.length - 3]);
|
||||||
|
const duration = String(parts[parts.length - 2] || '');
|
||||||
const name = parts.slice(1, -3).join('_').trim();
|
const name = parts.slice(1, -3).join('_').trim();
|
||||||
if (!name || !Number.isFinite(amount) || amount < 0) {
|
if (!name || !/^\d+天$/.test(duration) || !Number.isFinite(amount) || amount < 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
@ -638,35 +597,34 @@ async function uploadAsset(
|
|||||||
|
|
||||||
function processFiles(files: File[]) {
|
function processFiles(files: File[]) {
|
||||||
let accepted = 0;
|
let accepted = 0;
|
||||||
|
let ignored = 0;
|
||||||
files.forEach((file) => {
|
files.forEach((file) => {
|
||||||
const structuredFile = parseStructuredResourceFile(file);
|
const structuredFile = parseStructuredResourceFile(file);
|
||||||
if (structuredFile) {
|
if (!structuredFile) {
|
||||||
const row = findOrCreateRow(structuredFile.name, {
|
ignored += 1;
|
||||||
adminFree: false,
|
|
||||||
amount: structuredFile.amount,
|
|
||||||
amountTouched: true,
|
|
||||||
code: structuredFile.code,
|
|
||||||
type: structuredFile.type,
|
|
||||||
typeTouched: true,
|
|
||||||
});
|
|
||||||
setRowAsset(row, structuredFile.assetKind, file);
|
|
||||||
accepted += 1;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const kind = classifyFile(file);
|
const row = findOrCreateRow(structuredFile.name, {
|
||||||
if (!kind) {
|
adminFree: false,
|
||||||
return;
|
amount: structuredFile.amount,
|
||||||
}
|
amountTouched: true,
|
||||||
const row = findOrCreateRow(getFileBaseName(file));
|
code: structuredFile.code,
|
||||||
setRowAsset(row, kind, file);
|
type: structuredFile.type,
|
||||||
|
typeTouched: true,
|
||||||
|
});
|
||||||
|
setRowAsset(row, structuredFile.assetKind, file);
|
||||||
accepted += 1;
|
accepted += 1;
|
||||||
});
|
});
|
||||||
if (accepted === 0 && files.length > 0) {
|
if (accepted === 0 && files.length > 0) {
|
||||||
message.warning('未识别到可导入的封面或资源文件');
|
message.warning('未识别到符合命名规则的资源文件');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (accepted > 0) {
|
if (accepted > 0) {
|
||||||
message.success(`已导入 ${accepted} 个文件`);
|
message.success(
|
||||||
|
ignored > 0
|
||||||
|
? `已导入 ${accepted} 个文件,忽略 ${ignored} 个非规则文件`
|
||||||
|
: `已导入 ${accepted} 个文件`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user