Skip to content

Commit

Permalink
delete file
Browse files Browse the repository at this point in the history
  • Loading branch information
slavaGanzin committed Jul 29, 2023
1 parent 74fbf51 commit ca9db12
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
30 changes: 30 additions & 0 deletions front/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,36 @@ const onMount = (editor, monaco) => {
Editor = editor
monaco.editor.defineTheme('theme', rconf)
monaco.editor.setTheme('theme');
editor.addAction({
id: "Newfile",
label: "New File",

keybindings: [
monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyM,
],
precondition: null,
keybindingContext: null,
contextMenuGroupId: "navigation",
contextMenuOrder: 1.5,
run: function (ed) {
const file = prompt('Enter new filename')
if (file) {
ws.emit('file:save', { value: '', file })
ws.emit('file:list', {})
}
},
});

editor.addAction({
id: "deletefile",
label: "Delete File",
run: function (ed) {
ws.emit('file:delete', {file: State.selectedFile.name})
ws.emit('file:list', {})
},
});


editor.addAction({
id: "save",
label: "Save",
Expand Down
11 changes: 9 additions & 2 deletions rconf.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ for (const name of ['Sync', 'Server']) {
}


Server.on('file:delete', (ws, {file}) => {
fs.unlink(joinPath(DATADIR, file), console.log)
})

Server.on('file:save', (ws, {file, value}) => {
fs.writeFileSync(joinPath(DATADIR, file), value)
updateConfig()
Expand All @@ -275,8 +279,8 @@ Server.on('file:list', ws =>
)

const log = (message, ws, broadcastNode = false) => {
message.ip = ws._socket.remoteAddress.replace(/.*:(.*)/, '$1')
if (!message.id) message.id=message.ip
if (ws) message.ip = ws._socket.remoteAddress.replace(/.*:(.*)/, '$1')
if (ws && !message.id) message.id=message.ip
message.time = new Date()
if (message?.json?.status) {
message.status = message.json.status
Expand Down Expand Up @@ -327,6 +331,9 @@ Sync.on('config', (ws, {token, tags, platform, hash}) => {
return c
})

for (const p of ['uncaughtException', 'unhandledRejection', 'warning']) {
process.on(p, (error) => log({message: error.message, status: 'error'}))
}

app.listen(14141, () => {
mapObjIndexed((interfaces, name) => {
Expand Down

0 comments on commit ca9db12

Please sign in to comment.