Skip to content

Commit

Permalink
feat(exhentai): update list info in dist (#178)
Browse files Browse the repository at this point in the history
* feat(exhentai): update list info in dist

* chore: rename getWriteFilesPaths to getWriteMappingPaths
  • Loading branch information
orzyyyy committed Aug 20, 2019
1 parent 04c46e7 commit 8d52a39
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
8 changes: 4 additions & 4 deletions server/controller/DocumentController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Controller, Request } from '../utils/decorator';
import md5 from 'blueimp-md5';
import { getWriteFilesPaths, updateSider } from '../utils/document';
import { getWriteMappingPaths, updateSider } from '../utils/document';
import DocumentService from '../service/DocumentService';

export interface MappingProps {
Expand Down Expand Up @@ -46,7 +46,7 @@ export default class MarkdownController {
category,
});
// update layout for mapping, content for markdown
const writeFilesPaths = getWriteFilesPaths(category, id);
const writeFilesPaths = getWriteMappingPaths(category, id);
const originContent = service.getOriginContent(
writeFilesPaths[0],
layout,
Expand All @@ -62,7 +62,7 @@ export default class MarkdownController {
const service = new DocumentService();
const timeStamp = new Date().getTime();
const id = md5(timeStamp.toString());
const writeFilesPaths = getWriteFilesPaths(category, id);
const writeFilesPaths = getWriteMappingPaths(category, id);
service.updateMapping({
id,
title,
Expand All @@ -79,7 +79,7 @@ export default class MarkdownController {
async deleteTargetDocument(ctx: any) {
const { id, category } = ctx.request.body;
const service = new DocumentService();
const writeFilesPaths = getWriteFilesPaths(category, id);
const writeFilesPaths = getWriteMappingPaths(category, id);
service.deleteTargetDocument(writeFilesPaths);
service.updateMapping({ id }, true);
ctx.response.body = true;
Expand Down
5 changes: 4 additions & 1 deletion server/controller/ExhentaiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ export default class ExhentaiController {
const latestListInfo = await getLatestListInfo();
const results = await service.fetchListInfo(latestListInfo);
const createTime = getTimeStamp();
writeIntoJsonFile(`src/assets/exhentai/${createTime}`, results);
[
`src/assets/exhentai/${createTime}`,
`dist/assets/exhentai/${createTime}`,
].map(item => writeIntoJsonFile(item, results));
success('fetch completed.');
ctx.response.body = `./assets/exhentai/${createTime}.json`;
}
Expand Down
4 changes: 2 additions & 2 deletions server/service/DocumentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs-extra';
import omit from 'omit.js';
import prettier from 'prettier';
import { MappingProps } from '../controller/DocumentController';
import { getWriteFilesPaths } from '../utils/document';
import { getWriteMappingPaths } from '../utils/document';
import {
joinWithRootPath,
readJsonFile,
Expand Down Expand Up @@ -43,7 +43,7 @@ export default class DocumentService {
targetItem.id,
targetItem.category,
);
const writeFilesPaths = getWriteFilesPaths();
const writeFilesPaths = getWriteMappingPaths();
const mappingPath = joinWithRootPath(writeFilesPaths[0]);
if (!fs.existsSync(mappingPath)) {
fs.writeFileSync(mappingPath, []);
Expand Down
7 changes: 5 additions & 2 deletions server/utils/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ const updateSider = () => {
});
};

const getWriteFilesPaths = (category?: 'markdown' | 'mapping', id?: string) => {
const getWriteMappingPaths = (
category?: 'markdown' | 'mapping',
id?: string,
) => {
if (!id || !category) {
return [`src/assets/mapping.json`, `dist/assets/mapping.json`];
}
Expand All @@ -80,4 +83,4 @@ const getWriteFilesPaths = (category?: 'markdown' | 'mapping', id?: string) => {
];
};

export { getWriteFilesPaths, updateSider };
export { getWriteMappingPaths, updateSider };

0 comments on commit 8d52a39

Please sign in to comment.