mirror of
https://github.com/pvrzz/directify.git
synced 2026-11-29 05:22:24 +00:00
Add directify desktop app source
osu!lazer-style beatmap search (mode, mania key count, genre, language, star-rating range) against catboy.best-compatible mirrors with automatic fallback, library management with offline-cached cover art, a collection.db editor, portable beatpack backup/restore, i18n (en/es/ja), light/dark theme, keyboard shortcuts, proxy support, and an in-app GitHub Releases update check.
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "@directify/shared",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
"types": "./src/index.ts",
|
||||
"scripts": {
|
||||
"test": "vitest run",
|
||||
"lint": "tsc --noEmit"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.14.0",
|
||||
"typescript": "^5.6.0",
|
||||
"vitest": "^2.1.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { readCollectionDb, writeCollectionDb } from "./collection-db";
|
||||
import type { CollectionDatabase } from "./types";
|
||||
|
||||
describe("collection.db round-trip", () => {
|
||||
it("writes then reads back an identical structure", () => {
|
||||
const db: CollectionDatabase = {
|
||||
version: 20240101,
|
||||
collections: [
|
||||
{
|
||||
name: "Favorites",
|
||||
beatmapChecksums: [
|
||||
"a".repeat(32),
|
||||
"b".repeat(32),
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Empty collection",
|
||||
beatmapChecksums: [],
|
||||
},
|
||||
{
|
||||
name: "unicode ☆ collection 譜面",
|
||||
beatmapChecksums: ["c".repeat(32)],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const buf = writeCollectionDb(db);
|
||||
const roundTripped = readCollectionDb(buf);
|
||||
|
||||
expect(roundTripped).toEqual(db);
|
||||
});
|
||||
|
||||
it("produces byte-identical output when re-serialized", () => {
|
||||
const db: CollectionDatabase = {
|
||||
version: 20240101,
|
||||
collections: [{ name: "Test", beatmapChecksums: ["d".repeat(32)] }],
|
||||
};
|
||||
|
||||
const first = writeCollectionDb(db);
|
||||
const second = writeCollectionDb(readCollectionDb(first));
|
||||
|
||||
expect(second.equals(first)).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,145 @@
|
||||
import type { Collection, CollectionDatabase } from "./types";
|
||||
|
||||
/**
|
||||
* Reader/writer for osu!stable's `collection.db`.
|
||||
*
|
||||
* Format (little-endian):
|
||||
* int32 version
|
||||
* int32 collection count
|
||||
* for each collection:
|
||||
* string name
|
||||
* int32 beatmap count
|
||||
* for each beatmap:
|
||||
* string beatmap (.osu) MD5 checksum
|
||||
*
|
||||
* osu!-strings are a single marker byte (0x00 = null, 0x0b = present)
|
||||
* followed, when present, by a ULEB128-encoded byte length and the UTF-8 bytes.
|
||||
*/
|
||||
|
||||
const STRING_NULL = 0x00;
|
||||
const STRING_PRESENT = 0x0b;
|
||||
|
||||
class ByteReader {
|
||||
private offset = 0;
|
||||
constructor(private readonly buf: Buffer) {}
|
||||
|
||||
get bytesRemaining(): number {
|
||||
return this.buf.length - this.offset;
|
||||
}
|
||||
|
||||
readInt32(): number {
|
||||
const value = this.buf.readInt32LE(this.offset);
|
||||
this.offset += 4;
|
||||
return value;
|
||||
}
|
||||
|
||||
readByte(): number {
|
||||
const value = this.buf.readUInt8(this.offset);
|
||||
this.offset += 1;
|
||||
return value;
|
||||
}
|
||||
|
||||
private readUleb128(): number {
|
||||
let result = 0;
|
||||
let shift = 0;
|
||||
for (;;) {
|
||||
const byte = this.readByte();
|
||||
result |= (byte & 0x7f) << shift;
|
||||
if ((byte & 0x80) === 0) break;
|
||||
shift += 7;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
readString(): string | null {
|
||||
const marker = this.readByte();
|
||||
if (marker === STRING_NULL) return null;
|
||||
if (marker !== STRING_PRESENT) {
|
||||
throw new Error(`Unexpected osu!-string marker byte 0x${marker.toString(16)}`);
|
||||
}
|
||||
const length = this.readUleb128();
|
||||
const value = this.buf.toString("utf8", this.offset, this.offset + length);
|
||||
this.offset += length;
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
class ByteWriter {
|
||||
private chunks: Buffer[] = [];
|
||||
|
||||
writeInt32(value: number): this {
|
||||
const b = Buffer.alloc(4);
|
||||
b.writeInt32LE(value, 0);
|
||||
this.chunks.push(b);
|
||||
return this;
|
||||
}
|
||||
|
||||
writeByte(value: number): this {
|
||||
this.chunks.push(Buffer.from([value]));
|
||||
return this;
|
||||
}
|
||||
|
||||
private writeUleb128(value: number): this {
|
||||
const bytes: number[] = [];
|
||||
let v = value;
|
||||
do {
|
||||
let byte = v & 0x7f;
|
||||
v >>>= 7;
|
||||
if (v !== 0) byte |= 0x80;
|
||||
bytes.push(byte);
|
||||
} while (v !== 0);
|
||||
this.chunks.push(Buffer.from(bytes));
|
||||
return this;
|
||||
}
|
||||
|
||||
writeString(value: string | null | undefined): this {
|
||||
if (value === null || value === undefined) {
|
||||
return this.writeByte(STRING_NULL);
|
||||
}
|
||||
this.writeByte(STRING_PRESENT);
|
||||
const utf8 = Buffer.from(value, "utf8");
|
||||
this.writeUleb128(utf8.length);
|
||||
this.chunks.push(utf8);
|
||||
return this;
|
||||
}
|
||||
|
||||
toBuffer(): Buffer {
|
||||
return Buffer.concat(this.chunks);
|
||||
}
|
||||
}
|
||||
|
||||
export function readCollectionDb(buf: Buffer): CollectionDatabase {
|
||||
const reader = new ByteReader(buf);
|
||||
const version = reader.readInt32();
|
||||
const collectionCount = reader.readInt32();
|
||||
|
||||
const collections: Collection[] = [];
|
||||
for (let i = 0; i < collectionCount; i++) {
|
||||
const name = reader.readString() ?? "";
|
||||
const beatmapCount = reader.readInt32();
|
||||
const beatmapChecksums: string[] = [];
|
||||
for (let j = 0; j < beatmapCount; j++) {
|
||||
const checksum = reader.readString();
|
||||
if (checksum) beatmapChecksums.push(checksum);
|
||||
}
|
||||
collections.push({ name, beatmapChecksums });
|
||||
}
|
||||
|
||||
return { version, collections };
|
||||
}
|
||||
|
||||
export function writeCollectionDb(db: CollectionDatabase): Buffer {
|
||||
const writer = new ByteWriter();
|
||||
writer.writeInt32(db.version);
|
||||
writer.writeInt32(db.collections.length);
|
||||
|
||||
for (const collection of db.collections) {
|
||||
writer.writeString(collection.name);
|
||||
writer.writeInt32(collection.beatmapChecksums.length);
|
||||
for (const checksum of collection.beatmapChecksums) {
|
||||
writer.writeString(checksum);
|
||||
}
|
||||
}
|
||||
|
||||
return writer.toBuffer();
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "./types";
|
||||
export * from "./collection-db";
|
||||
@@ -0,0 +1,139 @@
|
||||
export type OsuMode = "osu" | "taiko" | "fruits" | "mania";
|
||||
|
||||
export type RankedStatus =
|
||||
| "graveyard"
|
||||
| "wip"
|
||||
| "pending"
|
||||
| "ranked"
|
||||
| "approved"
|
||||
| "qualified"
|
||||
| "loved"
|
||||
/** Status can't be determined from a local scan alone (no online lookup performed). */
|
||||
| "unknown";
|
||||
|
||||
/** A single difficulty within a beatmapset. */
|
||||
export interface Beatmap {
|
||||
id: number;
|
||||
beatmapsetId: number;
|
||||
version: string;
|
||||
mode: OsuMode;
|
||||
difficultyRating: number;
|
||||
bpm: number;
|
||||
totalLength: number;
|
||||
/** Circle size — also doubles as the key count for mania difficulties. */
|
||||
cs: number;
|
||||
ar: number;
|
||||
od: number;
|
||||
hp: number;
|
||||
/** MD5 of the .osu file, used as the key in osu!stable's collection.db. */
|
||||
checksum: string;
|
||||
}
|
||||
|
||||
/** A beatmapset as indexed from a source mirror. */
|
||||
export interface BeatmapSet {
|
||||
id: number;
|
||||
title: string;
|
||||
artist: string;
|
||||
creator: string;
|
||||
status: RankedStatus;
|
||||
coverUrl?: string;
|
||||
previewUrl?: string;
|
||||
tags: string[];
|
||||
genre?: string;
|
||||
language?: string;
|
||||
submittedAt: string;
|
||||
updatedAt: string;
|
||||
beatmaps: Beatmap[];
|
||||
/** Which source mirror this record was resolved from, or "local" for an installed scan. */
|
||||
source: string;
|
||||
/** Present for beatmapsets found on disk; the Songs subfolder name, used for file operations. */
|
||||
folderName?: string;
|
||||
}
|
||||
|
||||
/** osu!'s own genre enum (matches the IDs osu!/mirrors report; "any" omitted since it means "no filter"). */
|
||||
export const GENRES: Record<number, string> = {
|
||||
1: "Unspecified",
|
||||
2: "Video Game",
|
||||
3: "Anime",
|
||||
4: "Rock",
|
||||
5: "Pop",
|
||||
6: "Other",
|
||||
7: "Novelty",
|
||||
9: "Hip Hop",
|
||||
10: "Electronic",
|
||||
11: "Metal",
|
||||
12: "Classical",
|
||||
13: "Folk",
|
||||
14: "Jazz",
|
||||
};
|
||||
|
||||
/** osu!'s own language enum. */
|
||||
export const LANGUAGES: Record<number, string> = {
|
||||
1: "Unspecified",
|
||||
2: "English",
|
||||
3: "Japanese",
|
||||
4: "Chinese",
|
||||
5: "Instrumental",
|
||||
6: "Korean",
|
||||
7: "French",
|
||||
8: "German",
|
||||
9: "Swedish",
|
||||
10: "Spanish",
|
||||
11: "Italian",
|
||||
12: "Russian",
|
||||
13: "Polish",
|
||||
14: "Other",
|
||||
};
|
||||
|
||||
export interface BeatmapSearchQuery {
|
||||
query?: string;
|
||||
mode?: OsuMode;
|
||||
status?: RankedStatus;
|
||||
minStars?: number;
|
||||
maxStars?: number;
|
||||
/** Numeric genre id — see GENRES. */
|
||||
genre?: number;
|
||||
/** Numeric language id — see LANGUAGES. */
|
||||
language?: number;
|
||||
/** Mania key count (4, 7, ...) — matched against difficulty CS. Ignored unless mode is "mania". */
|
||||
keys?: number;
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
}
|
||||
|
||||
export interface BeatmapSearchResult {
|
||||
results: BeatmapSet[];
|
||||
page: number;
|
||||
pageSize: number;
|
||||
total: number;
|
||||
}
|
||||
|
||||
/** In-memory representation of an osu!stable collection. */
|
||||
export interface Collection {
|
||||
name: string;
|
||||
/** Beatmap (.osu) MD5 checksums belonging to this collection. */
|
||||
beatmapChecksums: string[];
|
||||
}
|
||||
|
||||
export interface CollectionDatabase {
|
||||
version: number;
|
||||
collections: Collection[];
|
||||
}
|
||||
|
||||
export interface BeatmapSourceConfig {
|
||||
id: string;
|
||||
name: string;
|
||||
baseUrl: string;
|
||||
builtIn?: boolean;
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
export type ThemeMode = "dark" | "light" | "system";
|
||||
|
||||
export type ProxyType = "none" | "http" | "https" | "socks4" | "socks5";
|
||||
|
||||
export interface ProxyConfig {
|
||||
type: ProxyType;
|
||||
host: string;
|
||||
port: string;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": "src"
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
Reference in New Issue
Block a user