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 { ...@@ -89,6 +89,9 @@ export class Participant extends NamedBase {
deckbuf?: string; deckbuf?: string;
isValidInCreate() { isValidInCreate() {
if (this['_invalid']) {
return this['_invalid'] as string;
}
if (this.deckbuf) { if (this.deckbuf) {
try { try {
const buf = Buffer.from(this.deckbuf, 'base64'); const buf = Buffer.from(this.deckbuf, 'base64');
......
...@@ -283,11 +283,30 @@ export class TournamentService extends CrudService(Tournament, { ...@@ -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( const deckObs = parseZipStream(
zipStreamRes.data, zipStreamRes.data,
(e) => e.type === 'File' && e.path.endsWith('.ydk'), (e) => e.type === 'File',
).pipe( ).pipe(
mergeMap(async (e) => { mergeMap(async (e) => {
if (!e.path.endsWith('.ydk')) {
// 非 YDK 文件,跳过
addInvalid(e.path, '非 YDK 文件');
e.autodrain();
return null;
}
try { try {
const content = await streamToBuffer(e); const content = await streamToBuffer(e);
...@@ -298,6 +317,7 @@ export class TournamentService extends CrudService(Tournament, { ...@@ -298,6 +317,7 @@ export class TournamentService extends CrudService(Tournament, {
}; };
} catch (err) { } catch (err) {
this.log.error(`Error reading file ${e.path}: ${err}`); this.log.error(`Error reading file ${e.path}: ${err}`);
addInvalid(e.path, '读取文件失败');
return null; return null;
} }
}), }),
...@@ -314,7 +334,9 @@ export class TournamentService extends CrudService(Tournament, { ...@@ -314,7 +334,9 @@ export class TournamentService extends CrudService(Tournament, {
.split('/') .split('/')
.pop() .pop()
.replace(/(\.ydk)+$/i, ''); .replace(/(\.ydk)+$/i, '');
if (!participant.name.length) return; if (!participant.name.length) {
participant['_invalid'] = '选手名称无效';
}
participant.tournamentId = id; participant.tournamentId = id;
participant.deckbuf = Buffer.from( participant.deckbuf = Buffer.from(
YGOProDeck.fromYdkString(text).toUpdateDeckPayload(), 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