mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-07-26 01:34:38 +10:00
Fix dev torrential server (#349)
* fix: droplet interface not waiting for torrential * fix: lint
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import type { CertificateStore } from "./ca-store";
|
import type { CertificateStore } from "./ca-store";
|
||||||
import { dropletInterface } from "../services/torrential/droplet-interface";
|
import { dropletInterface } from "../services/torrential/droplet-interface";
|
||||||
|
import { logger } from "../logging";
|
||||||
|
|
||||||
export type CertificateBundle = {
|
export type CertificateBundle = {
|
||||||
priv: string;
|
priv: string;
|
||||||
@@ -35,6 +36,8 @@ export class CertificateAuthority {
|
|||||||
await ca.generateClientCertificate("server", "Drop Server");
|
await ca.generateClientCertificate("server", "Drop Server");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info("initialised the ca");
|
||||||
|
|
||||||
return ca;
|
return ca;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -493,8 +493,8 @@ class LibraryManager {
|
|||||||
|
|
||||||
notificationSystem.systemPush({
|
notificationSystem.systemPush({
|
||||||
nonce: `version-create-${gameId}-${version}`,
|
nonce: `version-create-${gameId}-${version}`,
|
||||||
title: `'${game.mName}' ('${version}') finished importing.`,
|
title: `'${game.mName}' ('${version.name}') finished importing.`,
|
||||||
description: `Drop finished importing version ${version} for ${game.mName}.`,
|
description: `Drop finished importing version ${version.name} for ${game.mName}.`,
|
||||||
actions: [`View|/admin/library/${gameId}`],
|
actions: [`View|/admin/library/${gameId}`],
|
||||||
acls: ["system:import:version:read"],
|
acls: ["system:import:version:read"],
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ export class Service<T> {
|
|||||||
|
|
||||||
private uutils: T;
|
private uutils: T;
|
||||||
|
|
||||||
|
private readyPromise: Promise<void>;
|
||||||
|
private readyPromiseResolve: (() => void) | undefined;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
name: string,
|
name: string,
|
||||||
executor: Executor,
|
executor: Executor,
|
||||||
@@ -62,6 +65,9 @@ export class Service<T> {
|
|||||||
this.setup = setup;
|
this.setup = setup;
|
||||||
this.healthcheck = healthcheck;
|
this.healthcheck = healthcheck;
|
||||||
this.uutils = utils!;
|
this.uutils = utils!;
|
||||||
|
this.readyPromise = new Promise((r) => {
|
||||||
|
this.readyPromiseResolve = r;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
spin() {
|
spin() {
|
||||||
@@ -124,6 +130,8 @@ export class Service<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.healthy = true;
|
this.healthy = true;
|
||||||
|
if (this.readyPromiseResolve) this.readyPromiseResolve();
|
||||||
|
this.logger.info("service healthy");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,6 +165,10 @@ export class Service<T> {
|
|||||||
return this.healthy;
|
return this.healthy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async waitServiceHealthy() {
|
||||||
|
await this.readyPromise;
|
||||||
|
}
|
||||||
|
|
||||||
utils() {
|
utils() {
|
||||||
return this.uutils;
|
return this.uutils;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -250,6 +250,7 @@ class DropletInterfaceManager {
|
|||||||
messageType: TorrentialBoundType,
|
messageType: TorrentialBoundType,
|
||||||
callbackType: KT,
|
callbackType: KT,
|
||||||
): Promise<Parameters<Extract<K, { type: KT }>["resolve"]>[0]> {
|
): Promise<Parameters<Extract<K, { type: KT }>["resolve"]>[0]> {
|
||||||
|
await TORRENTIAL_SERVICE.waitServiceHealthy();
|
||||||
const messageId = crypto.randomUUID();
|
const messageId = crypto.randomUUID();
|
||||||
|
|
||||||
await TORRENTIAL_SERVICE.writeMessage(messageId, {
|
await TORRENTIAL_SERVICE.writeMessage(messageId, {
|
||||||
|
|||||||
@@ -59,7 +59,12 @@ export class TorrentialService extends Service<unknown> {
|
|||||||
);
|
);
|
||||||
return spawn(
|
return spawn(
|
||||||
"cargo",
|
"cargo",
|
||||||
["run", "--manifest-path", "./torrential/Cargo.toml"],
|
[
|
||||||
|
"run",
|
||||||
|
"--manifest-path",
|
||||||
|
"./torrential/Cargo.toml",
|
||||||
|
"--release",
|
||||||
|
],
|
||||||
{},
|
{},
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@@ -74,14 +79,15 @@ export class TorrentialService extends Service<unknown> {
|
|||||||
return spawn("torrential", [], {});
|
return spawn("torrential", [], {});
|
||||||
},
|
},
|
||||||
async () => {
|
async () => {
|
||||||
if (this.socket) return true;
|
const socket = net.createConnection({ port: 33148, host: "127.0.0.1" });
|
||||||
this.socket = net.createConnection({ port: 33148, host: "127.0.0.1" });
|
await new Promise<void>((r, j) => {
|
||||||
await new Promise<void>((r) =>
|
socket.on("connect", () => {
|
||||||
this.socket!.on("connect", () => {
|
|
||||||
this.logger.info("connected to torrential socket");
|
this.logger.info("connected to torrential socket");
|
||||||
|
this.socket = socket;
|
||||||
r();
|
r();
|
||||||
}),
|
});
|
||||||
);
|
socket.on("error", (err) => j(err));
|
||||||
|
});
|
||||||
|
|
||||||
this.setupRead();
|
this.setupRead();
|
||||||
return true;
|
return true;
|
||||||
@@ -129,6 +135,8 @@ export class TorrentialService extends Service<unknown> {
|
|||||||
data: T;
|
data: T;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
|
if (!this.socket) throw "Not connected to torrential";
|
||||||
|
|
||||||
const response = create(TorrentialBoundSchema, {
|
const response = create(TorrentialBoundSchema, {
|
||||||
messageId: messageId,
|
messageId: messageId,
|
||||||
type: value.type,
|
type: value.type,
|
||||||
@@ -146,6 +154,7 @@ export class TorrentialService extends Service<unknown> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async queueRead() {
|
private async queueRead() {
|
||||||
|
if (!this.socket) throw "Not connected to torrential";
|
||||||
if (this.readbuf.length < 8) return;
|
if (this.readbuf.length < 8) return;
|
||||||
const sizeBytes = this.readbuf.subarray(0, 8);
|
const sizeBytes = this.readbuf.subarray(0, 8);
|
||||||
const size = sizeBytes.readBigUInt64LE(0);
|
const size = sizeBytes.readBigUInt64LE(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user