Skip to content

Commit 63fa48e

Browse files
seki yoheiohtake
authored andcommitted
Add page deletion function
1 parent 85ab1f8 commit 63fa48e

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

server-websocket.js

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ function getInstanceOfY(room) {
6868
}
6969
return yInstances[room];
7070
}
71-
function removeInstanceOfY(room) {
72-
delete yInstances[room];
73-
delete metadata[room];
74-
}
7571

7672
function getSha1Hash(plaintext) {
7773
const sha1 = crypto.createHash('sha1');
@@ -97,13 +93,7 @@ router.post('/deletePage', async (req, res) => {
9793
res.setHeader('Access-Control-Allow-Origin', '*');
9894
res.setHeader('Content-Type', 'application/json');
9995
const room = req.body;
100-
const yPromise = yInstances[room];
101-
if (!yPromise) {
102-
res.end(JSON.stringify({ status: 'FAILURE', msg: 'No y instance' }));
103-
return;
104-
}
10596
try {
106-
const y = await yPromise;
10797
const roomMetadata = metadata[room];
10898
if (!roomMetadata) {
10999
res.end(JSON.stringify({ status: 'FAILURE', msg: 'No metadata' }));
@@ -113,17 +103,12 @@ router.post('/deletePage', async (req, res) => {
113103
res.end(JSON.stringify({ status: 'FAILURE', msg: 'There are still users on this page' }));
114104
return;
115105
}
116-
try {
117-
await y.destroy();
118-
removeInstanceOfY(room);
119-
res.end(JSON.stringify({ status: 'SUCCESS', msg: `Delete ${room}` }));
120-
} catch (ex) {
121-
console.error(ex);
122-
res.end(JSON.stringify({ status: 'FAILURE', msg: 'Y instance destroy error' }));
123-
}
106+
await LevelDBLib.deleteDatabase('y-leveldb-databases', room);
107+
delete metadata[room];
108+
res.end(JSON.stringify({ status: 'SUCCESS', msg: `Delete ${room}` }));
124109
} catch (ex) {
125110
console.error(ex);
126-
res.end(JSON.stringify({ status: 'FAILURE', msg: ex }));
111+
res.end(JSON.stringify({ status: 'FAILURE', msg: 'Failed to delete database' }));
127112
}
128113
});
129114

0 commit comments

Comments
 (0)