Skip to content

Commit

Permalink
Disable cleanup by default and show errors in admin area
Browse files Browse the repository at this point in the history
  • Loading branch information
Gared committed Sep 10, 2024
1 parent 593d102 commit 3330ed8
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 1 deletion.
21 changes: 21 additions & 0 deletions admin/src/pages/PadPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const PadPage = ()=>{
const pads = useStore(state=>state.pads)
const [currentPage, setCurrentPage] = useState<number>(0)
const [deleteDialog, setDeleteDialog] = useState<boolean>(false)
const [errorText, setErrorText] = useState<string|null>(null)
const [padToDelete, setPadToDelete] = useState<string>('')
const pages = useMemo(()=>{
if(!pads){
Expand Down Expand Up @@ -72,6 +73,11 @@ export const PadPage = ()=>{
settingsSocket.on('results:cleanupPadRevisions', (data)=>{
let newPads = useStore.getState().pads?.results ?? []

if (data.error) {
setErrorText(data.error)
return
}

newPads.forEach((pad)=>{
if (pad.padName === data.padId) {
pad.revisionNumber = data.keepRevisions
Expand Down Expand Up @@ -118,6 +124,21 @@ export const PadPage = ()=>{
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
<Dialog.Root open={errorText !== null}>
<Dialog.Portal>
<Dialog.Overlay className="dialog-confirm-overlay"/>
<Dialog.Content className="dialog-confirm-content">
<div>
<div>Error occured: {errorText}</div>
<div className="settings-button-bar">
<button onClick={() => {
setErrorText(null)
}}>OK</button>
</div>
</div>
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
<h1><Trans i18nKey="ep_admin_pads:ep_adminpads2_manage-pads"/></h1>
<SearchField value={searchTerm} onChange={v=>setSearchTerm(v.target.value)} placeholder={t('ep_admin_pads:ep_adminpads2_search-heading')}/>
<table>
Expand Down
8 changes: 8 additions & 0 deletions settings.json.docker
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@
*/
"showSettingsInAdminPage": "${SHOW_SETTINGS_IN_ADMIN_PAGE:true}",

/*
* Settings for cleanup of pads
*/
"cleanup": {
"enabled": false,
"keepRevisions": 5
},

/*
The authentication method used by the server.
The default value is sso
Expand Down
8 changes: 8 additions & 0 deletions settings.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@
*/
"showSettingsInAdminPage": true,

/*
* Settings for cleanup of pads
*/
"cleanup": {
"enabled": false,
"keepRevisions": 5
},

/*
* Node native SSL support
*
Expand Down
14 changes: 14 additions & 0 deletions src/node/hooks/express/adminsettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ exports.socketio = (hookName: string, {io}: any) => {
})

socket.on('cleanupPadRevisions', async (padId: string) => {
if (!settings.cleanup.enabled) {
socket.emit('results:cleanupPadRevisions', {
error: 'Cleanup disabled. Enable cleanup in settings.json: cleanup.enabled => true',
});
return;
}

const padExists = await padManager.doesPadExists(padId);
if (padExists) {
logger.info(`Cleanup pad revisions: ${padId}`);
Expand All @@ -265,9 +272,16 @@ exports.socketio = (hookName: string, {io}: any) => {
keepRevisions: settings.cleanup.keepRevisions,
});
logger.info('successful cleaned up pad: ', padId)
} else {
socket.emit('results:cleanupPadRevisions', {
error: 'Error cleaning up pad',
});
}
} catch (err: any) {
logger.error(`Error in pad ${padId}: ${err.stack || err}`);
socket.emit('results:cleanupPadRevisions', {
error: err.toString(),
});
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/node/utils/Cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ exports.deleteRevisions = async (padId: string, keepRevisions: number): Promise<

logger.debug('Initial pad is valid')

if (pad.head < keepRevisions) {
if (pad.head <= keepRevisions) {
logger.debug('Pad has not enough revisions')
return false
}
Expand Down
1 change: 1 addition & 0 deletions src/node/utils/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ exports.showSettingsInAdminPage = true;
* Settings for cleanup of pads
*/
exports.cleanup = {
enabled: false,
keepRevisions: 100,
}

Expand Down

0 comments on commit 3330ed8

Please sign in to comment.