Skip to content

Commit

Permalink
fix: DTO 버그 및 컨테이너 복사 붙여넣기로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
flydog98 committed Dec 7, 2023
1 parent 94da95c commit e48a80c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
18 changes: 18 additions & 0 deletions packages/backend/src/containers/containers.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ export class ContainersService {
const chownOriginCommand = `[ -d ~/origins/${quizId} ] && docker exec -u root ${containerId} chown -R ${user}:${user} /origin`;
const chownUpstreamCommand = `[ -d ~/upstreams/${quizId} ] && docker exec -u root ${containerId} chown -R ${user}:${user} /remote`;
const coreEditorCommand = `docker exec -w /home/quizzer/quiz/ -u ${user} ${containerId} git config --global core.editor /editor/output.sh`;
const containerDirectoryCommand = `mkdir /root/store/${containerId}`;
const containerDirectoryCpCommand = `docker cp ${containerId}:/home/quizzer/quiz/. /root/store/${containerId}/`;
await this.commandService.executeCommand(
createContainerCommand,
copyFilesCommand,
Expand All @@ -147,6 +149,8 @@ export class ContainersService {
chownOriginCommand,
chownUpstreamCommand,
coreEditorCommand,
containerDirectoryCommand,
containerDirectoryCpCommand,
);

return containerId;
Expand Down Expand Up @@ -260,4 +264,18 @@ export class ContainersService {
this.buildDockerCommand(containerId, ...commands),
);
}

async stashContainer(container: string): Promise<void> {
this.commandService.executeCommand(
`docker cp ${container}:/home/quizzer/quiz/. /root/store/${container}/`,
);
}

async stashPopContainer(container: string): Promise<void> {
this.commandService.executeCommand(
`docker exec -u quizzer -w /home/quizzer/ ${container} rm -rf quiz/.`,
`docker cp /root/store/${container} ${container}:/home/quizzer/quiz/.`,
`docker exec -u root ${container} chown -R quizzer:quizzer /home/quizzer`,
);
}
}
33 changes: 20 additions & 13 deletions packages/backend/src/quizzes/quizzes.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,18 @@ export class QuizzesController {
));

if (result === MODE.EDITOR) {
containerId = await this.containerService.getContainer(id);
await this.sessionService.setContainerBySessionId(
sessionId,
id,
containerId,
);
this.containerService.restoreContainer(
await this.sessionService.getLogObject(sessionId, id),
);
await this.containerService.stashPopContainer(containerId);
// containerId = await this.containerService.getContainer(id);
// await this.sessionService.setContainerBySessionId(
// sessionId,
// id,
// containerId,
// );
// this.containerService.restoreContainer(
// await this.sessionService.getLogObject(sessionId, id),
// );
} else {
await this.containerService.stashContainer(containerId);
}
} else if (execCommandDto.mode === MODE.EDITOR) {
// editor mode
Expand Down Expand Up @@ -445,12 +448,16 @@ export class QuizzesController {
async getGraphById(
@Param('id') id: number,
@SessionId() sessionId: string,
): Promise<any> {
): Promise<GraphDto> {
if (!sessionId) return JSON.parse(await this.quizService.getGraphById(id));

const graph = await this.sessionService.getGraphById(sessionId, id);
if (!graph) return JSON.parse(await this.quizService.getGraphById(id));

return graphParser(graph);
if (!graph) {
return JSON.parse(await this.quizService.getGraphById(id));
} else {
return {
graph: graphParser(graph),
};
}
}
}

0 comments on commit e48a80c

Please sign in to comment.