@soga/task 0.2.15 → 0.2.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,13 @@
1
- import { FileCache } from '@soga/file-cache';
2
1
  import { DataSource } from 'typeorm';
2
+ import { FileMeta, MediaMeta, SubtitleMeta } from './types';
3
+ import { LowType } from '@soga/bridge';
3
4
  export declare class SingleRunner {
4
- protected fc: FileCache;
5
+ db: LowType<DbDataType>;
5
6
  private file_id;
6
7
  private cache_file;
7
8
  private dataSource;
8
9
  private fileRepository;
9
- private PARSED_FILES_KEY;
10
- private INSERT_FOLDERS_KEY;
11
- private INSERT_FILES_KEY;
10
+ private calculateMd5;
12
11
  constructor({ dataSource, file_id, }: {
13
12
  dataSource: DataSource;
14
13
  file_id: number;
@@ -21,3 +20,14 @@ export declare class SingleRunner {
21
20
  private destroy;
22
21
  private init;
23
22
  }
23
+ type DbDataType = {
24
+ raw_files_parsed: boolean;
25
+ folders_inserted: boolean;
26
+ files_inserted: boolean;
27
+ folders: string[];
28
+ subtitles: SubtitleMeta[];
29
+ medias: MediaMeta[];
30
+ files: FileMeta[];
31
+ status: Record<string, boolean>;
32
+ };
33
+ export {};
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SingleRunner = void 0;
4
4
  const entities_1 = require("@soga/entities");
5
- const file_cache_1 = require("@soga/file-cache");
6
5
  const types_1 = require("@soga/types");
7
6
  const fs_extra_1 = require("fs-extra");
8
7
  const glob_1 = require("glob");
@@ -11,15 +10,19 @@ const path_1 = require("path");
11
10
  const typeorm_1 = require("typeorm");
12
11
  const fileinfo_1 = require("../utils/fileinfo");
13
12
  const utils_1 = require("./utils");
13
+ const bridge_1 = require("@soga/bridge");
14
+ const crypto_1 = require("crypto");
14
15
  class SingleRunner {
15
- fc;
16
+ db;
16
17
  file_id;
17
18
  cache_file;
18
19
  dataSource;
19
20
  fileRepository;
20
- PARSED_FILES_KEY = 'parsed_files';
21
- INSERT_FOLDERS_KEY = 'insert_folders';
22
- INSERT_FILES_KEY = 'insert_files';
21
+ calculateMd5(text) {
22
+ const hash = (0, crypto_1.createHash)('md5');
23
+ hash.update(`${text}`);
24
+ return hash.digest('hex');
25
+ }
23
26
  constructor({ dataSource, file_id, }) {
24
27
  this.dataSource = dataSource;
25
28
  this.fileRepository = dataSource.getRepository(entities_1.UploadFile);
@@ -48,12 +51,8 @@ class SingleRunner {
48
51
  await this.fileRepository.save(fileitem);
49
52
  }
50
53
  async insertFiles() {
51
- const key = this.INSERT_FILES_KEY;
52
- const cache = await this.fc.get(key);
53
- if (cache)
54
- return cache;
55
- const data = await this.fc.get(this.PARSED_FILES_KEY);
56
- if (!data)
54
+ const { files_inserted, files: normal_files, medias, subtitles, } = this.db.data;
55
+ if (files_inserted)
57
56
  return;
58
57
  const fileitem = await this.fileRepository.findOneBy({
59
58
  id: this.file_id,
@@ -63,7 +62,6 @@ class SingleRunner {
63
62
  const { config } = fileitem;
64
63
  const keep_source = config.file_keeps == types_1.RecordFileKeep.SOURCE ||
65
64
  config.file_keeps == types_1.RecordFileKeep.BOTH;
66
- const { subtitles, medias, files: normal_files } = data;
67
65
  const match_map = {};
68
66
  let subs = [...subtitles];
69
67
  medias.forEach((media) => {
@@ -162,17 +160,13 @@ class SingleRunner {
162
160
  finally {
163
161
  await queryRunner.release();
164
162
  }
165
- await this.fc.set(key, true);
163
+ this.db.data.files_inserted = true;
164
+ await this.db.write();
166
165
  }
167
166
  async insertFolders() {
168
- const key = this.INSERT_FOLDERS_KEY;
169
- const cache = await this.fc.get(key);
170
- if (cache)
171
- return cache;
172
- const data = await this.fc.get(this.PARSED_FILES_KEY);
173
- if (!data)
167
+ const { folders, folders_inserted } = this.db.data;
168
+ if (folders_inserted)
174
169
  return;
175
- const { folders } = data;
176
170
  const { length } = folders;
177
171
  const fileitem = await this.fileRepository.findOneBy({
178
172
  id: this.file_id,
@@ -230,13 +224,13 @@ class SingleRunner {
230
224
  };
231
225
  await this.fileRepository.save(this.fileRepository.create(info));
232
226
  }
233
- await this.fc.set(key, true);
227
+ this.db.data.folders_inserted = true;
228
+ await this.db.write();
234
229
  }
235
230
  async parseRawFiles() {
236
- const key = this.PARSED_FILES_KEY;
237
- const cache = await this.fc.get(key);
238
- if (cache)
239
- return cache;
231
+ if (this.db.data.raw_files_parsed) {
232
+ return;
233
+ }
240
234
  const fileitem = await this.fileRepository.findOneBy({
241
235
  id: this.file_id,
242
236
  });
@@ -308,19 +302,15 @@ class SingleRunner {
308
302
  }
309
303
  }
310
304
  }
311
- await this.fc.set(key, {
312
- files,
313
- folders,
314
- medias,
315
- subtitles,
316
- });
317
- return {
318
- files,
319
- folders,
320
- };
305
+ this.db.data.folders = folders;
306
+ this.db.data.files = files;
307
+ this.db.data.medias = medias;
308
+ this.db.data.subtitles = subtitles;
309
+ this.db.data.raw_files_parsed = true;
310
+ await this.db.write();
321
311
  }
322
312
  async destroy() {
323
- await this.fc?.destroy();
313
+ delete this.db;
324
314
  await (0, fs_extra_1.remove)(this.cache_file);
325
315
  }
326
316
  async init() {
@@ -329,9 +319,18 @@ class SingleRunner {
329
319
  });
330
320
  if (!fileitem)
331
321
  return;
332
- const { id } = fileitem;
333
- this.cache_file = (0, path_1.resolve)((0, os_1.homedir)(), '.dpan', 'desktop', 'json_files', `upload_task_single_${id}.json`);
334
- this.fc = await (0, file_cache_1.getFileCache)(this.cache_file);
322
+ const { id, inputs } = fileitem;
323
+ const input = inputs[0];
324
+ const md5 = this.calculateMd5(`${input.filepath}_${input.filesize}`);
325
+ this.cache_file = (0, path_1.resolve)((0, os_1.homedir)(), '.dpan', 'desktop', 'json_files', `${id}_${md5}.json`);
326
+ const defaultData = {
327
+ folders: [],
328
+ subtitles: [],
329
+ medias: [],
330
+ files: [],
331
+ status: {},
332
+ };
333
+ this.db = await (0, bridge_1.getDb)(this.cache_file, defaultData);
335
334
  }
336
335
  }
337
336
  exports.SingleRunner = SingleRunner;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soga/task",
3
- "version": "0.2.15",
3
+ "version": "0.2.22",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -47,17 +47,16 @@
47
47
  "author": "",
48
48
  "license": "ISC",
49
49
  "peerDependencies": {
50
- "level": "*",
51
50
  "typeorm": "*"
52
51
  },
53
52
  "dependencies": {
54
- "@soga/entities": "^0.2.15",
55
- "@soga/file-cache": "^0.2.13",
56
- "@soga/sdk": "^0.2.15",
57
- "@soga/types": "^0.2.15",
58
- "@soga/utils": "^0.2.15",
53
+ "@soga/bridge": "^0.2.22",
54
+ "@soga/entities": "^0.2.22",
55
+ "@soga/sdk": "^0.2.22",
56
+ "@soga/types": "^0.2.22",
57
+ "@soga/utils": "^0.2.22",
59
58
  "axios": "^1.8.4",
60
59
  "mime": "^3.0.0"
61
60
  },
62
- "gitHead": "2592173a0ca38f6ff55cbbc8e29d7b1ac4bb4072"
61
+ "gitHead": "6a9ab21995f575fd1325a2b5fa7eea4fd50564db"
63
62
  }