-29
src/pds.js
-29
src/pds.js
···
1364
1364
'/status': {
1365
1365
handler: (pds, _req, _url) => pds.handleStatus(),
1366
1366
},
1367
-
'/reset-repo': {
1368
-
handler: (pds, _req, _url) => pds.handleResetRepo(),
1369
-
},
1370
1367
'/forward-event': {
1371
1368
handler: (pds, req, _url) => pds.handleForwardEvent(req),
1372
1369
},
···
2028
2025
async handleStatus() {
2029
2026
const did = await this.getDid();
2030
2027
return Response.json({ initialized: !!did, did: did || null });
2031
-
}
2032
-
2033
-
async handleResetRepo() {
2034
-
const did = await this.getDid();
2035
-
if (!did) {
2036
-
return Response.json({ ok: true, message: 'no repo to reset', deleted: 0 });
2037
-
}
2038
-
2039
-
// Get all records before deleting
2040
-
const records = /** @type {{collection: string, rkey: string}[]} */ (
2041
-
this.sql.exec('SELECT collection, rkey FROM records').toArray()
2042
-
);
2043
-
2044
-
// Delete each record through normal flow (emits events to firehose)
2045
-
for (const { collection, rkey } of records) {
2046
-
await this.deleteRecord(collection, rkey);
2047
-
}
2048
-
2049
-
// Clean up remaining state
2050
-
this.sql.exec('DELETE FROM blocks');
2051
-
this.sql.exec('DELETE FROM commits');
2052
-
this.sql.exec('DELETE FROM seq_events');
2053
-
await this.state.storage.delete('head');
2054
-
await this.state.storage.delete('rev');
2055
-
2056
-
return Response.json({ ok: true, message: 'repo data cleared', deleted: records.length });
2057
2028
}
2058
2029
2059
2030
/** @param {Request} request */