-
Notifications
You must be signed in to change notification settings - Fork 0
/
progress.ts
33 lines (28 loc) · 874 Bytes
/
progress.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { join } from "https://deno.land/[email protected]/path/mod.ts";
import { Chapter } from "./metadata.ts";
interface Progress {
current: Chapter;
start: Chapter;
end: Chapter;
}
export function saveProgress(target_folder: string, progress: Progress): boolean {
const FILE_PATH = join(target_folder, "dl-progress");
const Encoder = new TextEncoder();
try {
Deno.writeFileSync(FILE_PATH, Encoder.encode(JSON.stringify(progress)), { create: true, append: false });
return true;
} catch (err) {
console.log(err);
return false;
}
}
export function loadProgress(target_folder: string) {
const FILE_PATH = join(target_folder, "dl-progress");
const Decoder = new TextDecoder();
try {
const progress: Progress = JSON.parse(Decoder.decode(Deno.readFileSync(FILE_PATH)));
return progress;
} catch (_e) {
return undefined;
}
}