mirror of
https://seed.radicle.dev/rad:z4D5UCArafTzTQpDZNQRuqswh3ury.git
synced 2026-11-29 14:50:34 +08:00
Check bare RIDs against already seeded repos
The seed form accepts a RID without the rad: prefix but compared it as typed against lists that have the prefix, so duplicates got through.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { parseRepositoryId } from "@app/lib/utils";
|
||||
|
||||
// Validates a RID typed into the "Seed a repo" form. The form accepts a bare
|
||||
// `z…` id as well as `rad:z…`, so the result is the RID in the `rad:` form the
|
||||
// seeded and queued lists use.
|
||||
export function seedTarget(
|
||||
input: string,
|
||||
queued: string[],
|
||||
seeded: string[],
|
||||
): { rid: string } | { error: string } {
|
||||
const parsed = parseRepositoryId(input.trim());
|
||||
if (parsed === undefined) {
|
||||
return { error: "RID is not valid" };
|
||||
}
|
||||
const rid = `${parsed.prefix}${parsed.pubkey}`;
|
||||
if (queued.includes(rid)) {
|
||||
return { error: "This repo is already queued for fetching" };
|
||||
}
|
||||
if (seeded.includes(rid)) {
|
||||
return { error: "This repo is already seeded" };
|
||||
}
|
||||
return { rid };
|
||||
}
|
||||
Reference in New Issue
Block a user