Skip to content

Commit

Permalink
eslint stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBrax committed Nov 28, 2023
1 parent 194ca35 commit 67d5825
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 111 deletions.
150 changes: 75 additions & 75 deletions server/src/Core/Job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,74 @@ export interface TwitchAutomatorJobJSON {
args?: string[];
}

export class Job extends EventEmitter {
interface JobEvents {
on(event: "update", listener: (job: ApiJob) => void): this;

on(event: "save", listener: () => void): this;

on(event: "clear", listener: (code: number | null) => void): this;

on(event: "close", listener: (code: number | null) => void): this;

on(event: "pre_clear", listener: () => void): this;

on(
event: "pid_set",
listener: (old_pid: number | undefined, new_pid: number) => void
): this;

on(
event: "process_set",
listener: (
old_process: ChildProcessWithoutNullStreams | undefined,
new_process: ChildProcessWithoutNullStreams
) => void
): this;

on(
event: "metadata_set",
listener: (
old_metadata: Record<string, unknown> | undefined,
new_metadata: Record<string, unknown>
) => void
): this;

on(
event: "metadata_add",
listener: (
old_metadata: Record<string, unknown> | undefined,
new_metadata: Record<string, unknown>
) => void
): this;

on(event: "pre_kill", listener: (method: NodeJS.Signals) => void): this;

on(event: "process_start", listener: () => void): this;

on(
event: "process_exit",
listener: (code: number | null, signal: NodeJS.Signals) => void
): this;

on(event: "process_error", listener: (err: Error) => void): this;

/** @deprecated */
on(
event: "process_close",
listener: (code: number | null, signal: NodeJS.Signals) => void
): this;

on(event: "stdout", listener: (data: string) => void): this;

on(event: "stderr", listener: (data: string) => void): this;

on(
event: "log",
listener: (type: "stdout" | "stderr", data: string) => void
): this;
}

export class Job extends EventEmitter implements JobEvents {
static jobs: Job[] = [];
static pidstatus: Record<number, boolean> = {};

Expand Down Expand Up @@ -64,14 +131,13 @@ export class Job extends EventEmitter {

public dummy = false;

logfile = "";
public logfile = "";

private _updateTimer: NodeJS.Timeout | undefined;
private _progressTimer: NodeJS.Timeout | undefined;

private realpath(str: string): string {
return path.normalize(str);
}
private progressAccumulator = 0; // FIXME: i hate this implementation
private progressUpdatesCleared = 0;

public static loadJobsFromCache() {
const jobs = fs
Expand Down Expand Up @@ -199,7 +265,7 @@ export class Job extends EventEmitter {
return false;
}

const data: TwitchAutomatorJobJSON = JSON.parse(raw);
const data = JSON.parse(raw) as TwitchAutomatorJobJSON;

job.pid = data.pid;
job.dt_started_at = data.dt_started_at
Expand Down Expand Up @@ -903,9 +969,6 @@ export class Job extends EventEmitter {
}
}

private progressAccumulator = 0; // FIXME: i hate this implementation
private progressUpdatesCleared = 0;

public setProgress(progress: number): void {
if (progress > this.progress) {
// console.debug(`Job ${this.name} progress: ${progress}`);
Expand Down Expand Up @@ -1094,71 +1157,8 @@ export class Job extends EventEmitter {
});
});
}
}

export declare interface Job {
on(event: "update", listener: (job: ApiJob) => void): this;

on(event: "save", listener: () => void): this;

on(event: "clear", listener: (code: number | null) => void): this;

on(event: "close", listener: (code: number | null) => void): this;

on(event: "pre_clear", listener: () => void): this;

on(
event: "pid_set",
listener: (old_pid: number | undefined, new_pid: number) => void
): this;

on(
event: "process_set",
listener: (
old_process: ChildProcessWithoutNullStreams | undefined,
new_process: ChildProcessWithoutNullStreams
) => void
): this;

on(
event: "metadata_set",
listener: (
old_metadata: Record<string, unknown> | undefined,
new_metadata: Record<string, unknown>
) => void
): this;

on(
event: "metadata_add",
listener: (
old_metadata: Record<string, unknown> | undefined,
new_metadata: Record<string, unknown>
) => void
): this;

on(event: "pre_kill", listener: (method: NodeJS.Signals) => void): this;

on(event: "process_start", listener: () => void): this;

on(
event: "process_exit",
listener: (code: number | null, signal: NodeJS.Signals) => void
): this;

on(event: "process_error", listener: (err: Error) => void): this;

/** @deprecated */
on(
event: "process_close",
listener: (code: number | null, signal: NodeJS.Signals) => void
): this;

on(event: "stdout", listener: (data: string) => void): this;

on(event: "stderr", listener: (data: string) => void): this;

on(
event: "log",
listener: (type: "stdout" | "stderr", data: string) => void
): this;
private realpath(str: string): string {
return path.normalize(str);
}
}
3 changes: 2 additions & 1 deletion server/src/Core/Providers/Base/BaseChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { ExporterOptions } from "@common/Exporter";
import type { LocalClip } from "@common/LocalClip";
import type { LocalVideo } from "@common/LocalVideo";
import type { AudioMetadata, VideoMetadata } from "@common/MediaInfo";
import type { Clip } from "@common/TwitchAPI/Clips";
import type { ChannelUpdated } from "@common/Webhook";
import type chokidar from "chokidar";
import { format } from "date-fns";
Expand Down Expand Up @@ -633,7 +634,7 @@ export class BaseChannel {
clipPath.replace(".mp4", ".info.json"),
"utf8"
)
);
) as Clip;
} catch (error) {
log(
LOGLEVEL.ERROR,
Expand Down
30 changes: 15 additions & 15 deletions server/src/Core/Providers/Twitch/TwitchAutomator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ export class TwitchAutomator extends BaseAutomator {

const messageId = metadata.message_id;
const messageRetry = metadata.message_retry;
const messageType = metadata.message_type;
const messageSignature = metadata.message_signature;
const messageTimestamp = metadata.message_timestamp;
const subscriptionType = metadata.subscription_type;
const subscriptionVersion = metadata.subscription_version;
// const messageType = metadata.message_type;
// const messageSignature = metadata.message_signature;
// const messageTimestamp = metadata.message_timestamp;
// const subscriptionType = metadata.subscription_type;
// const subscriptionVersion = metadata.subscription_version;

if (messageRetry !== undefined && messageRetry > 0) {
log(
Expand Down Expand Up @@ -120,8 +120,8 @@ export class TwitchAutomator extends BaseAutomator {
// this.payload_headers = request.headers;

const subscription = data.subscription;
const subscription_type = subscription.type;
const subscription_id = subscription.id;
const subscriptionType = subscription.type;
const subscriptionId = subscription.id;

// this.data_cache = data;

Expand All @@ -134,18 +134,18 @@ export class TwitchAutomator extends BaseAutomator {
this.broadcaster_user_login
);

if (subscription_type === "channel.update") {
if (subscriptionType === "channel.update") {
// check if channel is in config, copypaste
if (!TwitchChannel.getChannelByLogin(this.broadcaster_user_login)) {
log(
LOGLEVEL.ERROR,
"automator.handle",
`Handle (update) triggered with sub id ${subscription_id}, but username '${this.broadcaster_user_login}' is not in config.`
`Handle (update) triggered with sub id ${subscriptionId}, but username '${this.broadcaster_user_login}' is not in config.`
);

// 5head solution
// TwitchHelper.channelUnsubscribe($this->broadcaster_user_id);
TwitchHelper.eventSubUnsubscribe(subscription_id);
void TwitchHelper.eventSubUnsubscribe(subscriptionId);
return false;
}

Expand All @@ -162,7 +162,7 @@ export class TwitchAutomator extends BaseAutomator {
);

return await this.updateGame();
} else if (subscription_type == "stream.online") {
} else if (subscriptionType == "stream.online") {
if (!("id" in event)) {
log(
LOGLEVEL.ERROR,
Expand Down Expand Up @@ -195,12 +195,12 @@ export class TwitchAutomator extends BaseAutomator {
log(
LOGLEVEL.ERROR,
"automator.handle",
`Handle (online) triggered with sub id ${subscription_id}, but username '${this.broadcaster_user_login}' is not in config.`
`Handle (online) triggered with sub id ${subscriptionId}, but username '${this.broadcaster_user_login}' is not in config.`
);

// 5head solution
// TwitchHelper.channelUnsubscribe($this->broadcaster_user_id);
TwitchHelper.eventSubUnsubscribe(subscription_id);
void TwitchHelper.eventSubUnsubscribe(subscriptionId);
return false;
}

Expand Down Expand Up @@ -353,7 +353,7 @@ export class TwitchAutomator extends BaseAutomator {
}

return true;
} else if (subscription_type == "stream.offline") {
} else if (subscriptionType == "stream.offline") {
KeyValue.getInstance().setBool(
`${this.broadcaster_user_login}.offline`,
true
Expand All @@ -364,7 +364,7 @@ export class TwitchAutomator extends BaseAutomator {
log(
LOGLEVEL.ERROR,
"automator.handle",
`No supported subscription type (${subscription_type}).`
`No supported subscription type (${subscriptionType}).`
);
return false;
}
Expand Down
11 changes: 8 additions & 3 deletions server/src/Core/Providers/Twitch/TwitchGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ export class TwitchGame {
"game.populateGameDatabase",
"Populating game database..."
);

this.game_db = {};
const rawGames: Record<string, TwitchGameJSON> = JSON.parse(

const rawGames = JSON.parse(
fs.readFileSync(BaseConfigPath.gameDb, "utf8")
);
) as Record<string, TwitchGameJSON>;

for (const id in rawGames) {
const rawGame = rawGames[id];
const game = new this();
Expand Down Expand Up @@ -71,9 +74,11 @@ export class TwitchGame {
"game.populateFavouriteGames",
"Populating favourite games..."
);

this.favourite_games = JSON.parse(
fs.readFileSync(BaseConfigPath.favouriteGames, "utf8")
);
) as string[];

log(
LOGLEVEL.INFO,
"game.populateFavouriteGames",
Expand Down
Loading

0 comments on commit 67d5825

Please sign in to comment.