Skip to content

Commit

Permalink
Merge pull request #222 from Noodlez1232/master
Browse files Browse the repository at this point in the history
Misc. fixes to make packaging easier
  • Loading branch information
Inrixia authored Dec 24, 2024
2 parents 88c7197 + 90ea9a3 commit 687269b
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 192 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@
"postject": "1.0.0-alpha.6",
"typescript": "^5.7.0-beta"
}
}
}
334 changes: 170 additions & 164 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sea-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"assets": {
"./version": "./dist/version"
}
}
}
4 changes: 2 additions & 2 deletions src/lib/Attachment.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import db from "@inrixia/db";
import { nPad } from "@inrixia/helpers/math";
import { ValueOfA } from "@inrixia/helpers/ts";
import { settings } from "./helpers/index.js";
import { settings, args } from "./helpers/index.js";
import sanitize from "sanitize-filename";

import { dirname, basename, extname } from "path";
Expand Down Expand Up @@ -32,7 +32,7 @@ enum Extensions {
}

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

public readonly attachmentId: string;
Expand Down
2 changes: 2 additions & 0 deletions src/lib/Video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { ProgressHeadless } from "./logging/ProgressConsole.js";
import { ProgressBars } from "./logging/ProgressBars.js";
import { nll, withContext } from "./logging/ProgressLogger.js";

import { ffmpegPath } from "./helpers/fetchFFMPEG.js";

const exec = promisify(execCallback);
const sleep = promisify(setTimeout);

Expand Down
3 changes: 3 additions & 0 deletions src/lib/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export const defaultArgs: Args = {
plexUsername: "",
plexPassword: "",
sanityCheck: false,
dbPath: "./db",
ffmpegPath: "",
settingsPath: "",
};

export const defaultSettings: Settings = {
Expand Down
9 changes: 6 additions & 3 deletions src/lib/helpers/fetchFFMPEG.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { downloadBinaries, detectPlatform, getBinaryFilename } from "ffbinaries";
import { args } from "./index.js";
import fs from "fs";
import { dirname } from "path";

export const ffmpegPath = args.ffmpegPath || `${args.dbPath}/${getBinaryFilename("ffmpeg", detectPlatform())}`;

export const fetchFFMPEG = (): Promise<void> =>
new Promise((resolve, reject) => {
const platform = detectPlatform();
const path = "./db/";
if (fs.existsSync(`${path}${getBinaryFilename("ffmpeg", platform)}`) === false) {
if (!fs.existsSync(ffmpegPath)) {
process.stdout.write("> Ffmpeg binary missing! Downloading... ");
downloadBinaries(
"ffmpeg",
{
destination: path,
destination: dirname(ffmpegPath),
platform,
},
(err) => {
Expand Down
47 changes: 26 additions & 21 deletions src/lib/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getEnv, rebuildTypes, recursiveUpdate } from "@inrixia/helpers/object";
import { getEnv, recursiveUpdate, rebuildTypes } from "@inrixia/helpers/object";
import { defaultArgs, defaultSettings } from "../defaults.js";
import { Histogram } from "prom-client";
import db from "@inrixia/db";
Expand All @@ -22,9 +22,33 @@ import type { PartialArgs, Settings } from "../types.js";

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

import { Floatplane } from "floatplane";

const argv = ARGV(process.argv.slice(2))<PartialArgs>({});
const env = getEnv();

export const args = { ...defaultArgs };
recursiveUpdate(args, env, { setUndefined: false, setDefined: true });
recursiveUpdate(args, argv, { setUndefined: false, setDefined: true });
rebuildTypes(args, defaultArgs);

const settingsPath = args.settingsPath || `${args.dbPath}/settings.json`;

export const settings = { ...defaultSettings };
const newSettings = db<Settings>(settingsPath, { template: defaultSettings, pretty: true, forceCreate: true, updateOnExternalChanges: true });
recursiveUpdate(settings, newSettings, { setUndefined: true, setDefined: true });
recursiveUpdate(settings, argv, { setUndefined: false, setDefined: true });
rebuildTypes(settings, defaultSettings);

if (env.__FPDSettings !== undefined) {
if (typeof env.__FPDSettings !== "string") throw new Error("The __FPDSettings environment variable cannot be parsed!");
recursiveUpdate(settings, parse(env.__FPDSettings.replaceAll('\\"', '"')), { setUndefined: false, setDefined: true });
}

recursiveUpdate(settings, env, { setUndefined: false, setDefined: true });

export const cookieJar = new CookieJar(new FileCookieStore(`${args.dbPath}/cookies.json`));
export const fApi = new Floatplane(
cookieJar,
`Floatplane-Downloader/${DownloaderVersion} (Inrix, +https://github.com/Inrixia/Floatplane-Downloader), CFNetwork`,
Expand Down Expand Up @@ -58,25 +82,6 @@ fApi.extend({
},
});

export const settings = db<Settings>("./db/settings.json", { template: defaultSettings, pretty: true, forceCreate: true, updateOnExternalChanges: true });
recursiveUpdate(settings, defaultSettings);

const argv = ARGV(process.argv.slice(2))<PartialArgs>({});
rebuildTypes(argv, { ...defaultSettings, ...defaultArgs });
recursiveUpdate(settings, argv, { setUndefined: false, setDefined: true });

const env = getEnv();
rebuildTypes(env, { ...defaultSettings, ...defaultArgs });

if (env.__FPDSettings !== undefined) {
if (typeof env.__FPDSettings !== "string") throw new Error("The __FPDSettings environment variable cannot be parsed!");
recursiveUpdate(settings, parse(env.__FPDSettings.replaceAll('\\"', '"')), { setUndefined: false, setDefined: true });
}

recursiveUpdate(settings, env, { setUndefined: false, setDefined: true });

export const args = { ...argv, ...env };

// eslint-disable-next-line no-control-regex
const headlessStdoutRegex = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
// Override stdout if headless to not include formatting tags
Expand Down
3 changes: 3 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export type Args = {
plexUsername: string;
plexPassword: string;
sanityCheck: boolean;
dbPath: string;
ffmpegPath: string;
settingsPath: string;
};

export type PartialArgs = Partial<Args & Settings>;
Expand Down

0 comments on commit 687269b

Please sign in to comment.