Skip to content

Commit 687269b

Browse files
authored
Merge pull request #222 from Noodlez1232/master
Misc. fixes to make packaging easier
2 parents 88c7197 + 90ea9a3 commit 687269b

File tree

9 files changed

+214
-192
lines changed

9 files changed

+214
-192
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@
6464
"postject": "1.0.0-alpha.6",
6565
"typescript": "^5.7.0-beta"
6666
}
67-
}
67+
}

pnpm-lock.yaml

Lines changed: 170 additions & 164 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sea-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
"assets": {
77
"./version": "./dist/version"
88
}
9-
}
9+
}

src/lib/Attachment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import db from "@inrixia/db";
22
import { nPad } from "@inrixia/helpers/math";
33
import { ValueOfA } from "@inrixia/helpers/ts";
4-
import { settings } from "./helpers/index.js";
4+
import { settings, args } from "./helpers/index.js";
55
import sanitize from "sanitize-filename";
66

77
import { dirname, basename, extname } from "path";
@@ -32,7 +32,7 @@ enum Extensions {
3232
}
3333

3434
export class Attachment implements AttachmentAttributes {
35-
private static readonly AttachmentsDB: Record<string, AttachmentInfo> = db<Record<string, AttachmentInfo>>(`./db/attachments.json`);
35+
private static readonly AttachmentsDB: Record<string, AttachmentInfo> = db<Record<string, AttachmentInfo>>(`${args.dbPath}/attachments.json`);
3636
public static readonly Extensions = Extensions;
3737

3838
public readonly attachmentId: string;

src/lib/Video.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import { ProgressHeadless } from "./logging/ProgressConsole.js";
2525
import { ProgressBars } from "./logging/ProgressBars.js";
2626
import { nll, withContext } from "./logging/ProgressLogger.js";
2727

28+
import { ffmpegPath } from "./helpers/fetchFFMPEG.js";
29+
2830
const exec = promisify(execCallback);
2931
const sleep = promisify(setTimeout);
3032

src/lib/defaults.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export const defaultArgs: Args = {
3434
plexUsername: "",
3535
plexPassword: "",
3636
sanityCheck: false,
37+
dbPath: "./db",
38+
ffmpegPath: "",
39+
settingsPath: "",
3740
};
3841

3942
export const defaultSettings: Settings = {

src/lib/helpers/fetchFFMPEG.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import { downloadBinaries, detectPlatform, getBinaryFilename } from "ffbinaries";
2+
import { args } from "./index.js";
23
import fs from "fs";
4+
import { dirname } from "path";
5+
6+
export const ffmpegPath = args.ffmpegPath || `${args.dbPath}/${getBinaryFilename("ffmpeg", detectPlatform())}`;
37

48
export const fetchFFMPEG = (): Promise<void> =>
59
new Promise((resolve, reject) => {
610
const platform = detectPlatform();
7-
const path = "./db/";
8-
if (fs.existsSync(`${path}${getBinaryFilename("ffmpeg", platform)}`) === false) {
11+
if (!fs.existsSync(ffmpegPath)) {
912
process.stdout.write("> Ffmpeg binary missing! Downloading... ");
1013
downloadBinaries(
1114
"ffmpeg",
1215
{
13-
destination: path,
16+
destination: dirname(ffmpegPath),
1417
platform,
1518
},
1619
(err) => {

src/lib/helpers/index.ts

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getEnv, rebuildTypes, recursiveUpdate } from "@inrixia/helpers/object";
1+
import { getEnv, recursiveUpdate, rebuildTypes } from "@inrixia/helpers/object";
22
import { defaultArgs, defaultSettings } from "../defaults.js";
33
import { Histogram } from "prom-client";
44
import db from "@inrixia/db";
@@ -22,9 +22,33 @@ import type { PartialArgs, Settings } from "../types.js";
2222

2323
import { FileCookieStore } from "tough-cookie-file-store";
2424
import { CookieJar } from "tough-cookie";
25-
export const cookieJar = new CookieJar(new FileCookieStore("./db/cookies.json"));
2625

2726
import { Floatplane } from "floatplane";
27+
28+
const argv = ARGV(process.argv.slice(2))<PartialArgs>({});
29+
const env = getEnv();
30+
31+
export const args = { ...defaultArgs };
32+
recursiveUpdate(args, env, { setUndefined: false, setDefined: true });
33+
recursiveUpdate(args, argv, { setUndefined: false, setDefined: true });
34+
rebuildTypes(args, defaultArgs);
35+
36+
const settingsPath = args.settingsPath || `${args.dbPath}/settings.json`;
37+
38+
export const settings = { ...defaultSettings };
39+
const newSettings = db<Settings>(settingsPath, { template: defaultSettings, pretty: true, forceCreate: true, updateOnExternalChanges: true });
40+
recursiveUpdate(settings, newSettings, { setUndefined: true, setDefined: true });
41+
recursiveUpdate(settings, argv, { setUndefined: false, setDefined: true });
42+
rebuildTypes(settings, defaultSettings);
43+
44+
if (env.__FPDSettings !== undefined) {
45+
if (typeof env.__FPDSettings !== "string") throw new Error("The __FPDSettings environment variable cannot be parsed!");
46+
recursiveUpdate(settings, parse(env.__FPDSettings.replaceAll('\\"', '"')), { setUndefined: false, setDefined: true });
47+
}
48+
49+
recursiveUpdate(settings, env, { setUndefined: false, setDefined: true });
50+
51+
export const cookieJar = new CookieJar(new FileCookieStore(`${args.dbPath}/cookies.json`));
2852
export const fApi = new Floatplane(
2953
cookieJar,
3054
`Floatplane-Downloader/${DownloaderVersion} (Inrix, +https://github.com/Inrixia/Floatplane-Downloader), CFNetwork`,
@@ -58,25 +82,6 @@ fApi.extend({
5882
},
5983
});
6084

61-
export const settings = db<Settings>("./db/settings.json", { template: defaultSettings, pretty: true, forceCreate: true, updateOnExternalChanges: true });
62-
recursiveUpdate(settings, defaultSettings);
63-
64-
const argv = ARGV(process.argv.slice(2))<PartialArgs>({});
65-
rebuildTypes(argv, { ...defaultSettings, ...defaultArgs });
66-
recursiveUpdate(settings, argv, { setUndefined: false, setDefined: true });
67-
68-
const env = getEnv();
69-
rebuildTypes(env, { ...defaultSettings, ...defaultArgs });
70-
71-
if (env.__FPDSettings !== undefined) {
72-
if (typeof env.__FPDSettings !== "string") throw new Error("The __FPDSettings environment variable cannot be parsed!");
73-
recursiveUpdate(settings, parse(env.__FPDSettings.replaceAll('\\"', '"')), { setUndefined: false, setDefined: true });
74-
}
75-
76-
recursiveUpdate(settings, env, { setUndefined: false, setDefined: true });
77-
78-
export const args = { ...argv, ...env };
79-
8085
// eslint-disable-next-line no-control-regex
8186
const headlessStdoutRegex = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
8287
// Override stdout if headless to not include formatting tags

src/lib/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ export type Args = {
3333
plexUsername: string;
3434
plexPassword: string;
3535
sanityCheck: boolean;
36+
dbPath: string;
37+
ffmpegPath: string;
38+
settingsPath: string;
3639
};
3740

3841
export type PartialArgs = Partial<Args & Settings>;

0 commit comments

Comments
 (0)