-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: separate side effect operations to service from controller (#…
…98) * try: inject services to controller * refactor(ExhentaiController): getLastestExHentaiSet & getThumbnaiInfo * refactor(ExhentaiController): download * refactor(DocumentController): combine Markdown and Mapping controller * refactor(MainPageController): add service * refactor(DocumentController): add, update, delete
- Loading branch information
Showing
18 changed files
with
595 additions
and
563 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { Controller, Request } from '../utils/decorator'; | ||
import md5 from 'blueimp-md5'; | ||
import { getWriteFilesPaths } from '../utils/document'; | ||
import DocumentService from '../service/DocumentService'; | ||
|
||
export interface MappingProps { | ||
[x: string]: any; | ||
createTime?: number; | ||
modifyTime?: number; | ||
id: string; | ||
title?: string; | ||
url?: string; | ||
type?: string; | ||
subType?: string; | ||
category?: 'mapping' | 'markdown'; | ||
} | ||
|
||
@Controller('/document') | ||
export default class MarkdownController { | ||
@Request({ url: '/update', method: 'post' }) | ||
async updateTargetDocument(ctx: any) { | ||
const { layout, id, title, type, subType, category } = ctx.request.body; | ||
if (!id) { | ||
throw Error('id is undefined'); | ||
} | ||
const service = new DocumentService(); | ||
// update mapping | ||
service.updateMapping({ | ||
id, | ||
title, | ||
modifyTime: new Date().getTime(), | ||
type, | ||
subType, | ||
category, | ||
}); | ||
// update layout for mapping, content for markdown | ||
const writeFilesPaths = getWriteFilesPaths(category, id); | ||
const originContent = service.getOriginContent( | ||
writeFilesPaths[0], | ||
layout, | ||
id, | ||
); | ||
service.updateContent(category, writeFilesPaths, originContent); | ||
ctx.response.body = true; | ||
} | ||
|
||
@Request({ url: '/add', method: 'post' }) | ||
async initDocument(ctx: any) { | ||
const { title, type, subType, category } = ctx.request.body; | ||
const service = new DocumentService(); | ||
const timeStamp = new Date().getTime(); | ||
const id = md5(timeStamp.toString()); | ||
const writeFilesPaths = getWriteFilesPaths(category, id); | ||
service.updateMapping({ | ||
id, | ||
title, | ||
type, | ||
subType, | ||
category, | ||
}); | ||
service.updateContent(category, writeFilesPaths); | ||
ctx.response.body = id; | ||
} | ||
|
||
@Request({ url: '/delete', method: 'delete' }) | ||
async deleteTargetDocument(ctx: any) { | ||
const { id, category } = ctx.request.body; | ||
const service = new DocumentService(); | ||
const writeFilesPaths = getWriteFilesPaths(category, id); | ||
service.deleteTargetDocument(writeFilesPaths); | ||
service.updateMapping({ id }, true); | ||
ctx.response.body = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.