chore(repo): prune dead code and duplicate abstractions (#3413)

This commit is contained in:
Hampus authored and GitHub committed 2026-10-12 13:09:42 +02:00
1 parent c17091768c
commit c9fdf8fead
2937 files changed
+42233 -176793

No files matched your search

@@ -3,7 +3,7 @@
import Initialization from '@app/features/app/state/Initialization';
import Accounts from '@app/features/auth/state/Accounts';
import DeveloperOptions from '@app/features/devtools/state/DeveloperOptions';
import GatewayConnection from '@app/features/gateway/transport/GatewayConnection';
import GatewaySessions from '@app/features/gateway/transport/GatewaySessionPool';
export function isClientBooting(): boolean {
if (DeveloperOptions.bypassLoadingSkeleton) {
@@ -19,5 +19,5 @@ export function isClientReconnecting(): boolean {
if (isClientBooting() || Accounts.transitioning) {
return false;
}
return GatewayConnection.isConnectionInterrupted || !Initialization.isReady;
return GatewaySessions.foregroundConnection.isConnectionInterrupted || !Initialization.isReady;
}
@@ -1,78 +0,0 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {DEPLOYED_OFFICIAL_DOCUMENT} from '@fluxer/instance_bootstrap/src/__tests__/DiscoveryFixtures';
import {
fetchInstanceDiscovery,
InstanceDiscoveryOriginMismatchError,
InstanceDiscoveryUnreachableError,
} from '@fluxer/instance_bootstrap/src/Discovery';
import {describe, expect, it} from 'vitest';
function serve(document: unknown): typeof globalThis.fetch {
return (async () =>
new Response(JSON.stringify(document), {
status: 200,
headers: {'content-type': 'application/json'},
})) as unknown as typeof globalThis.fetch;
}
function documentWithEndpoints(overrides: Record<string, string>): unknown {
return {
...DEPLOYED_OFFICIAL_DOCUMENT,
endpoints: {...DEPLOYED_OFFICIAL_DOCUMENT.endpoints, ...overrides},
};
}
describe('a discovery document must declare the origin that served it', () => {
it('accepts the official document fetched from the official API host', async () => {
const result = await fetchInstanceDiscovery({
input: 'https://api.fluxer.app',
fetch: serve(DEPLOYED_OFFICIAL_DOCUMENT),
});
expect(result.kind).toBe('ok');
});
it('accepts a self-hosted document whose API is a path on the serving origin', async () => {
const result = await fetchInstanceDiscovery({
input: 'https://self.hosted.example',
fetch: serve(
documentWithEndpoints({
api: 'https://self.hosted.example/api',
api_client: 'https://self.hosted.example/api',
api_public: 'https://self.hosted.example/api',
}),
),
});
expect(result.kind).toBe('ok');
});
it('refuses a document that claims the official API while served by someone else', async () => {
await expect(
fetchInstanceDiscovery({input: 'https://evil.example', fetch: serve(DEPLOYED_OFFICIAL_DOCUMENT)}),
).rejects.toBeInstanceOf(InstanceDiscoveryUnreachableError);
await expect(
fetchInstanceDiscovery({input: 'https://evil.example', fetch: serve(DEPLOYED_OFFICIAL_DOCUMENT)}),
).rejects.toThrow(/declared an API at https:\/\/api\.fluxer\.app/u);
});
it('refuses a document whose api_client points somewhere other than the origin that served it', async () => {
await expect(
fetchInstanceDiscovery({
input: 'https://self.hosted.example',
fetch: serve(
documentWithEndpoints({
api: 'https://self.hosted.example/api',
api_client: 'https://api.fluxer.app',
api_public: 'https://self.hosted.example/api',
}),
),
}),
).rejects.toBeInstanceOf(InstanceDiscoveryUnreachableError);
});
it('carries both origins on the mismatch error', () => {
const error = new InstanceDiscoveryOriginMismatchError('https://evil.example', 'https://api.fluxer.app');
expect(error.servedBy).toBe('https://evil.example');
expect(error.declared).toBe('https://api.fluxer.app');
});
});
@@ -20,7 +20,6 @@ const STOCKHOLM = {
latitude: '59.3293',
longitude: '18.0686',
ageRestrictedGeos: [],
ageBlockedGeos: [],
};
interface Instance {
@@ -120,7 +119,6 @@ test('the served age policy seeds both tables before anything is fetched', async
installRuntime(documentFor(instance, SWEDEN_BLOCKS_STOCKHOLM));
const GeoIP = await loadGeoIP();
expect(GeoIP.ageRestrictedGeos).toEqual([]);
expect(GeoIP.ageBlockedGeos).toEqual([{countryCode: 'SE', regionCode: 'AB'}]);
expect(instance.requests).toEqual([]);
await GeoIP.ready();
});
@@ -133,7 +131,6 @@ test('a document with no age policy falls back to the bundled table', async () =
{countryCode: 'GB', regionCode: null},
{countryCode: 'BR', regionCode: null},
]);
expect(GeoIP.ageBlockedGeos).toEqual([{countryCode: 'US', regionCode: 'MS'}]);
await GeoIP.ready();
});
@@ -162,7 +159,6 @@ test('no active runtime never reaches the network and stays age gated', async ()
{countryCode: 'GB', regionCode: null},
{countryCode: 'BR', regionCode: null},
]);
expect(GeoIP.ageBlockedGeos).toEqual([{countryCode: 'US', regionCode: 'MS'}]);
});
test('a failed lookup leaves the gateway free to supply the country', async () => {
@@ -199,14 +195,12 @@ test('switching to another instance re-seeds the tables and re-resolves against
]);
await GeoIP.ready();
expect(GeoIP.countryCode).toBe('SE');
expect(GeoIP.ageBlockedGeos).toEqual([{countryCode: 'SE', regionCode: 'AB'}]);
RuntimeConfig.applySnapshot(
runtimeSnapshotFromDiscovery(parseInstanceDiscoveryDocument(documentFor(second, UK_ONLY))),
);
expect(GeoIP.resolution).toBe('pending');
expect(GeoIP.ageRestrictedGeos).toEqual([{countryCode: 'GB', regionCode: null}]);
expect(GeoIP.ageBlockedGeos).toEqual([]);
await GeoIP.ready();
expect(lookups(second)).toEqual(['GET /api/ip']);
expect(GeoIP.countryCode).toBe('GB');
@@ -232,7 +226,6 @@ test('installing the first runtime re-seeds and resolves', async () => {
expect(lookups(instance)).toEqual(['GET /api/ip']);
expect(GeoIP.resolution).toBe('resolved');
expect(GeoIP.countryCode).toBe('SE');
expect(GeoIP.ageBlockedGeos).toEqual([{countryCode: 'SE', regionCode: 'AB'}]);
});
test('an instance that cannot geolocate never wipes a country the gateway already supplied', async () => {
+4 -10
View File
@@ -3,7 +3,7 @@
import {runtimeInstanceKey} from '@app/features/app/state/InstanceSnapshotStore';
import RuntimeConfig from '@app/features/app/state/RuntimeConfig';
import {Logger} from '@app/features/platform/utils/AppLogger';
import {AGE_BLOCKED_GEOS, AGE_RESTRICTED_GEOS} from '@fluxer/instance_bootstrap/src/AgeGeos';
import {AGE_RESTRICTED_GEOS} from '@fluxer/instance_bootstrap/src/AgeGeos';
import type {GeoEntry, GeolocationResponse, InstanceAgePolicy} from '@fluxer/instance_bootstrap/src/Types';
import {compareStructural, makeAutoObservable, reaction, runInAction} from 'mobx';
@@ -21,7 +21,6 @@ interface ConnectionGeo {
interface AgeTables {
restricted: ReadonlyArray<GeoEntry>;
blocked: ReadonlyArray<GeoEntry>;
}
interface ActiveRuntimeContext {
@@ -32,19 +31,16 @@ interface ActiveRuntimeContext {
function ageTablesFor(policy: InstanceAgePolicy | null): AgeTables {
if (policy == null) {
return {restricted: AGE_RESTRICTED_GEOS, blocked: AGE_BLOCKED_GEOS};
return {restricted: AGE_RESTRICTED_GEOS};
}
const restricted: Array<GeoEntry> = [];
const blocked: Array<GeoEntry> = [];
for (const geo of policy.geos) {
const entry: GeoEntry = {countryCode: geo.country_code, regionCode: geo.region_code};
if (geo.action === 'block') {
blocked.push(entry);
} else {
if (geo.action !== 'block') {
restricted.push(entry);
}
}
return {restricted, blocked};
return {restricted};
}
function activeRuntimeContext(): ActiveRuntimeContext | null {
@@ -86,7 +82,6 @@ class GeoIP {
latitude: string | null = null;
longitude: string | null = null;
ageRestrictedGeos: ReadonlyArray<GeoEntry> = AGE_RESTRICTED_GEOS;
ageBlockedGeos: ReadonlyArray<GeoEntry> = AGE_BLOCKED_GEOS;
resolution: GeoIPResolution = 'pending';
private generation = 0;
private instanceKey: string | null = null;
@@ -173,7 +168,6 @@ class GeoIP {
private applyAgeTables(tables: AgeTables): void {
this.ageRestrictedGeos = tables.restricted;
this.ageBlockedGeos = tables.blocked;
}
private async resolve(): Promise<void> {
@@ -1,43 +0,0 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {makeAutoObservable} from 'mobx';
export const InstanceResponseCapability = Object.freeze({
HANDOFF_POLL_SECRET: 'handoffPollSecret',
} as const);
export type InstanceResponseCapability = (typeof InstanceResponseCapability)[keyof typeof InstanceResponseCapability];
type InstanceResponseObservations = Readonly<Partial<Record<InstanceResponseCapability, boolean>>>;
interface ObserveInstanceResponseRequest {
readonly instanceKey: string;
readonly capability: InstanceResponseCapability;
readonly supported: boolean;
}
class InstanceCapabilitiesStore {
private records: Map<string, InstanceResponseObservations> = new Map();
constructor() {
makeAutoObservable(this, {}, {autoBind: true});
}
observedSupport(instanceKey: string, capability: InstanceResponseCapability): boolean | null {
return this.records.get(instanceKey)?.[capability] ?? null;
}
observeResponse({instanceKey, capability, supported}: ObserveInstanceResponseRequest): void {
const responses = this.records.get(instanceKey);
if (responses != null && responses[capability] === supported) {
return;
}
this.records.set(instanceKey, {...responses, [capability]: supported});
}
forget(instanceKey: string): void {
this.records.delete(instanceKey);
}
}
export default new InstanceCapabilitiesStore();
@@ -15,19 +15,11 @@ class ResettableStateRegistry {
private readonly logger = new Logger('ResettableStates');
private readonly resets = new Map<object, () => void>();
register(store: object, reset: () => void): () => void {
register(store: object, reset: () => void): void {
if (this.resets.has(store)) {
throw new ResettableStateAlreadyRegisteredError();
}
this.resets.set(store, reset);
let registered = true;
return () => {
if (!registered) {
return;
}
registered = false;
this.resets.delete(store);
};
}
resetAll(): void {
+2 -6
View File
@@ -27,6 +27,7 @@ import {
} from '@app/features/updater/state/UpdaterStateMachine';
import {buildLinuxManualUpdateOptions} from '@app/features/updater/utils/LinuxManualUpdateOptions';
import type {UpdaterEvent as NativeUpdaterEvent, UpdaterDownloadOption} from '@app/types/electron.d';
import {OFFICIAL_WEB_APP_HOSTS} from '@fluxer/instance_bootstrap/src/OfficialWebAppHosts';
import {makeAutoObservable, runInAction} from 'mobx';
type UpdaterContext = NonNullable<NativeUpdaterEvent['context']>;
@@ -70,12 +71,7 @@ const WEB_CHECK_TIMEOUT_MS = 15 * 1000;
const NATIVE_CHECK_TIMEOUT_MS = 30 * 1000;
const VERSION_ENDPOINT = '/version.json';
const CURRENT_BUILD_VERSION = Config.PUBLIC_BUILD_VERSION ?? null;
const ALLOWED_WEB_UPDATE_HOSTS = new Set([
'web.fluxer.app',
'web.canary.fluxer.app',
'fluxer.com',
'canary.fluxer.com',
]);
const ALLOWED_WEB_UPDATE_HOSTS = new Set<string>(OFFICIAL_WEB_APP_HOSTS);
function loadUpdaterModals(): Promise<typeof UpdaterModalCommands> {
return import('@app/features/updater/commands/UpdaterModalCommands');