Make transferred names disabled, make setting name enable it
This commit is contained in:
parent
9c80939e59
commit
d5bf5a0faf
|
@ -0,0 +1,16 @@
|
||||||
|
-- RedefineTables
|
||||||
|
PRAGMA foreign_keys=OFF;
|
||||||
|
CREATE TABLE "new_Names" (
|
||||||
|
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"name" TEXT NOT NULL,
|
||||||
|
"npub" TEXT NOT NULL,
|
||||||
|
"timestamp" BIGINT NOT NULL,
|
||||||
|
"disabled" INTEGER NOT NULL DEFAULT 0
|
||||||
|
);
|
||||||
|
INSERT INTO "new_Names" ("id", "name", "npub", "timestamp") SELECT "id", "name", "npub", "timestamp" FROM "Names";
|
||||||
|
DROP TABLE "Names";
|
||||||
|
ALTER TABLE "new_Names" RENAME TO "Names";
|
||||||
|
CREATE UNIQUE INDEX "Names_name_key" ON "Names"("name");
|
||||||
|
CREATE INDEX "Names_npub_idx" ON "Names"("npub");
|
||||||
|
PRAGMA foreign_key_check;
|
||||||
|
PRAGMA foreign_keys=ON;
|
|
@ -30,6 +30,7 @@ model Names {
|
||||||
name String @unique
|
name String @unique
|
||||||
npub String
|
npub String
|
||||||
timestamp BigInt
|
timestamp BigInt
|
||||||
|
disabled Int @default(0)
|
||||||
|
|
||||||
@@index([npub])
|
@@index([npub])
|
||||||
}
|
}
|
||||||
|
|
29
src/index.js
29
src/index.js
|
@ -801,8 +801,24 @@ app.post(NAME_PATH, async (req, res) => {
|
||||||
const alreadyAssigned = names.find((n) => n.name === name);
|
const alreadyAssigned = names.find((n) => n.name === name);
|
||||||
if (alreadyAssigned) {
|
if (alreadyAssigned) {
|
||||||
console.log("Name", name, "already assigned to", npub);
|
console.log("Name", name, "already assigned to", npub);
|
||||||
|
|
||||||
|
const status = alreadyAssigned.disabled ? 201 : 200;
|
||||||
|
if (alreadyAssigned.disabled) {
|
||||||
|
const dbr = await prisma.names.update({
|
||||||
|
where: {
|
||||||
|
npub,
|
||||||
|
name
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
timestamp: Date.now(),
|
||||||
|
disabled: 0
|
||||||
|
},
|
||||||
|
});
|
||||||
|
console.log("Name", name, "activated for", npub, { dbr });
|
||||||
|
}
|
||||||
|
|
||||||
// reply ok
|
// reply ok
|
||||||
res.status(200).send({
|
res.status(status).send({
|
||||||
ok: true,
|
ok: true,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
|
@ -855,7 +871,7 @@ app.get(NAME_PATH, async (req, res) => {
|
||||||
console.log("npub", npub, recs);
|
console.log("npub", npub, recs);
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
names: recs.map((r) => r.name),
|
names: recs.filter((r) => !r.disabled).map((r) => r.name),
|
||||||
};
|
};
|
||||||
|
|
||||||
res.status(200).send(data);
|
res.status(200).send(data);
|
||||||
|
@ -874,7 +890,7 @@ app.delete(NAME_PATH, async (req, res) => {
|
||||||
if (!(await verifyAuthNostr(req, npub, NAME_PATH))) {
|
if (!(await verifyAuthNostr(req, npub, NAME_PATH))) {
|
||||||
console.log("auth failed", npub);
|
console.log("auth failed", npub);
|
||||||
res.status(403).send({
|
res.status(403).send({
|
||||||
error: `Bad auth`
|
error: `Bad auth`,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -923,7 +939,7 @@ app.put(NAME_PATH, async (req, res) => {
|
||||||
if (!(await verifyAuthNostr(req, npub, NAME_PATH))) {
|
if (!(await verifyAuthNostr(req, npub, NAME_PATH))) {
|
||||||
console.log("auth failed", npub);
|
console.log("auth failed", npub);
|
||||||
res.status(403).send({
|
res.status(403).send({
|
||||||
error: `Bad auth`
|
error: `Bad auth`,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -950,6 +966,7 @@ app.put(NAME_PATH, async (req, res) => {
|
||||||
npub: newNpub,
|
npub: newNpub,
|
||||||
name,
|
name,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
|
disabled: 1,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
console.log({ dbr });
|
console.log({ dbr });
|
||||||
|
@ -964,7 +981,6 @@ app.put(NAME_PATH, async (req, res) => {
|
||||||
res.status(201).send({
|
res.status(201).send({
|
||||||
ok: true,
|
ok: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(new Date(), "error req from ", req.ip, e.toString());
|
console.log(new Date(), "error req from ", req.ip, e.toString());
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
|
@ -973,7 +989,6 @@ app.put(NAME_PATH, async (req, res) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const JSON_PATH = "/.well-known/nostr.json";
|
const JSON_PATH = "/.well-known/nostr.json";
|
||||||
app.get(JSON_PATH, async (req, res) => {
|
app.get(JSON_PATH, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
@ -1001,7 +1016,7 @@ app.get(JSON_PATH, async (req, res) => {
|
||||||
});
|
});
|
||||||
console.log("name", name, rec);
|
console.log("name", name, rec);
|
||||||
|
|
||||||
if (rec) {
|
if (rec && !rec.disabled) {
|
||||||
const { data: pubkey } = nip19.decode(rec.npub);
|
const { data: pubkey } = nip19.decode(rec.npub);
|
||||||
data.names[rec.name] = pubkey;
|
data.names[rec.name] = pubkey;
|
||||||
data.nip46[pubkey] = [BUNKER_RELAY];
|
data.nip46[pubkey] = [BUNKER_RELAY];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user