Skip to content

Commit cbe48ca

Browse files
committed
Added DELETE method for one-to-many mode
1 parent ae7b635 commit cbe48ca

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

api/helper.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ export async function privateProduce(privateKey, data){
6666
return kv.set(dbKey, data, { ex: ttl });
6767
}
6868

69+
export async function privateDelete(privateKey){
70+
const publicKey = genPublicKey(privateKey);
71+
const dbKey = dbKeyPrefix.oneToMany + publicKey;
72+
return kv.del(dbKey);
73+
}
74+
6975
export async function publicConsume(publicKey){
7076
const dbKey = dbKeyPrefix.oneToMany + publicKey;
7177
return kv.get(dbKey);

api/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ fastify.post('/private/:privateKey', async (request, reply) => {
106106
}
107107
})
108108

109+
fastify.delete('/private/:privateKey', async (request, reply) => {
110+
const { privateKey } = request.params;
111+
try {
112+
if (helper.validate(privateKey) !== 'private') throw 401;
113+
await helper.privateDelete(privateKey);
114+
reply.code(204);
115+
} catch (err) {
116+
if (err == 401) {
117+
callUnauthorized(reply, 'Provided key is not Private');
118+
} else {
119+
callInternalServerError(reply, err);
120+
}
121+
}
122+
})
123+
109124
fastify.get('/public/:publicKey', async (request, reply) => {
110125
const { publicKey } = request.params;
111126
try {

0 commit comments

Comments
 (0)