优化发布截图上传与押金提示
This commit is contained in:
@@ -28,7 +28,7 @@ export function buildPublishDraft(options: {
|
||||
form: PublishForm
|
||||
quantityValues: Record<QuantityKey, number>
|
||||
quantityModes: Record<QuantityKey, ChargeMode>
|
||||
screenshotFiles: Record<ScreenshotKey, string>
|
||||
screenshotFiles: Record<ScreenshotKey, string[]>
|
||||
selectedSkins: string[]
|
||||
}): PublishDraft {
|
||||
return {
|
||||
@@ -38,7 +38,7 @@ export function buildPublishDraft(options: {
|
||||
},
|
||||
quantityValues: { ...options.quantityValues },
|
||||
quantityModes: { ...options.quantityModes },
|
||||
screenshotFiles: { ...options.screenshotFiles },
|
||||
screenshotFiles: cloneScreenshotFiles(options.screenshotFiles),
|
||||
selectedSkins: [...options.selectedSkins],
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ export function readPublishDraft(draftKey: string) {
|
||||
form: normalizeDraftForm(draft.form),
|
||||
quantityValues: normalizeNumberRecord(draft.quantityValues),
|
||||
quantityModes: normalizeQuantityModes(draft.quantityModes),
|
||||
screenshotFiles: normalizeStringRecord(draft.screenshotFiles),
|
||||
screenshotFiles: normalizeScreenshotFiles(draft.screenshotFiles),
|
||||
selectedSkins: Array.isArray(draft.selectedSkins)
|
||||
? draft.selectedSkins.filter((skin): skin is string => typeof skin === 'string')
|
||||
: [],
|
||||
@@ -105,15 +105,25 @@ function normalizeNumberRecord(value: unknown) {
|
||||
return record
|
||||
}
|
||||
|
||||
function normalizeStringRecord(value: unknown) {
|
||||
const record: Record<string, string> = {}
|
||||
function normalizeScreenshotFiles(value: unknown) {
|
||||
const record: Record<string, string[]> = {}
|
||||
if (!isRecord(value)) return record
|
||||
for (const [key, item] of Object.entries(value)) {
|
||||
if (typeof item === 'string') record[key] = item
|
||||
if (typeof item === 'string') {
|
||||
record[key] = item ? [item] : []
|
||||
continue
|
||||
}
|
||||
if (Array.isArray(item)) {
|
||||
record[key] = item.filter((url): url is string => typeof url === 'string' && Boolean(url))
|
||||
}
|
||||
}
|
||||
return record
|
||||
}
|
||||
|
||||
function cloneScreenshotFiles(value: Record<string, string[]>) {
|
||||
return Object.fromEntries(Object.entries(value).map(([key, urls]) => [key, [...urls]]))
|
||||
}
|
||||
|
||||
function normalizeQuantityModes(value: unknown) {
|
||||
const record: Record<string, ChargeMode> = {}
|
||||
if (!isRecord(value)) return record
|
||||
|
||||
Reference in New Issue
Block a user