refactor: use native async discovery and simplify shared state
This commit is contained in:
1 parent
5032cbb8c0
commit
4e2b6b1200
87 files changed
+2063
-2002
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { fromHex, toHex } from '@snowluma/common/hex';
|
||||
import { mapWithConcurrency } from '@snowluma/common/concurrency';
|
||||
import { positiveIntEnv } from '@snowluma/common/env';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
@@ -3275,7 +3276,7 @@ export const actions = [
|
||||
);
|
||||
}
|
||||
|
||||
const body = hexToBytes(p.data);
|
||||
const body = fromHex(p.data);
|
||||
const result = await ctx.bridge.sendRawPacket(p.cmd, body);
|
||||
|
||||
if (!result.success) {
|
||||
@@ -3286,7 +3287,7 @@ export const actions = [
|
||||
return okResponse(null);
|
||||
}
|
||||
|
||||
const respHex = result.responseData ? bytesToHex(result.responseData) : '';
|
||||
const respHex = result.responseData ? toHex(result.responseData) : '';
|
||||
return okResponse(respHex);
|
||||
},
|
||||
}),
|
||||
@@ -3577,21 +3578,6 @@ async function fetchFilteredGroupRequests(ctx: ApiActionContext) {
|
||||
return ctx.bridge.apis.contacts.fetchGroupRequests(true);
|
||||
}
|
||||
|
||||
function hexToBytes(hex: string): Uint8Array {
|
||||
const out = new Uint8Array(hex.length / 2);
|
||||
|
||||
for (let i = 0; i < out.length; i++) {
|
||||
out[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
function bytesToHex(buf: Buffer | Uint8Array): string {
|
||||
const arr = buf instanceof Buffer ? buf : Buffer.from(buf);
|
||||
return arr.toString('hex');
|
||||
}
|
||||
|
||||
function parseDownloadHeaders(headers: unknown): Record<string, string> {
|
||||
const result: Record<string, string> = {};
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { errorMessage } from '@snowluma/common/errors';
|
||||
// Stream API file actions (#163) — NapCat-compatible chunked file transfer.
|
||||
//
|
||||
// upload_file_stream: a client (possibly on another machine) pushes a file to
|
||||
@@ -531,7 +532,3 @@ export const __test = {
|
||||
MAX_CONCURRENT_STREAMS,
|
||||
MAX_CHUNKS,
|
||||
};
|
||||
|
||||
function errorMessage(error: unknown): string {
|
||||
return error instanceof Error ? error.message : String(error);
|
||||
}
|
||||
Reference in new issue
Block a user