Commit 8863ec48 authored by nanahira's avatar nanahira

fix

parent c913fda2
Pipeline #36621 passed with stages
in 42 seconds
......@@ -89,6 +89,9 @@ export class Participant extends NamedBase {
deckbuf?: string;
isValidInCreate() {
if (this['_invalid']) {
return this['_invalid'] as string;
}
if (this.deckbuf) {
try {
const buf = Buffer.from(this.deckbuf, 'base64');
......
......@@ -283,11 +283,30 @@ export class TournamentService extends CrudService(Tournament, {
});
}
const addInvalid = (name: string, reason: string) => {
const participant = new Participant();
participant.name = name
.split('/')
.pop()
.replace(/(\.ydk)+$/i, '');
participant.tournamentId = id;
participant.quit = false;
participant.deckbuf = undefined;
participant['_invalid'] = reason;
participants.push(participant);
};
const deckObs = parseZipStream(
zipStreamRes.data,
(e) => e.type === 'File' && e.path.endsWith('.ydk'),
(e) => e.type === 'File',
).pipe(
mergeMap(async (e) => {
if (!e.path.endsWith('.ydk')) {
// 非 YDK 文件,跳过
addInvalid(e.path, '非 YDK 文件');
e.autodrain();
return null;
}
try {
const content = await streamToBuffer(e);
......@@ -298,6 +317,7 @@ export class TournamentService extends CrudService(Tournament, {
};
} catch (err) {
this.log.error(`Error reading file ${e.path}: ${err}`);
addInvalid(e.path, '读取文件失败');
return null;
}
}),
......@@ -314,7 +334,9 @@ export class TournamentService extends CrudService(Tournament, {
.split('/')
.pop()
.replace(/(\.ydk)+$/i, '');
if (!participant.name.length) return;
if (!participant.name.length) {
participant['_invalid'] = '选手名称无效';
}
participant.tournamentId = id;
participant.deckbuf = Buffer.from(
YGOProDeck.fromYdkString(text).toUpdateDeckPayload(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment