Skip to content

Commit

Permalink
webui delete syncpoint by api key
Browse files Browse the repository at this point in the history
  • Loading branch information
gotson committed Aug 27, 2024
1 parent 11286c4 commit 8e5652f
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 2 deletions.
33 changes: 33 additions & 0 deletions komga-webui/src/components/ApiKeyTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@
<v-list-item-subtitle v-else>{{ $t('settings_user.no_recent_activity') }}</v-list-item-subtitle>
</v-list-item-content>

<v-list-item-action>
<v-tooltip bottom>
<template v-slot:activator="{ on }">
<v-btn icon @click="promptSyncPointDelete(apiKey)" v-on="on">
<v-icon>mdi-book-refresh</v-icon>
</v-btn>
</template>
<span>{{ $t('account_settings.api_key.force_kobo_sync') }}</span>
</v-tooltip>
</v-list-item-action>

<v-list-item-action>
<v-btn icon @click="promptDeleteApiKey(apiKey)">
<v-icon>mdi-delete</v-icon>
Expand Down Expand Up @@ -70,6 +81,15 @@
</v-container>
</div>

<confirmation-dialog
v-model="modalDeleteSyncPoints"
:title="$t('dialog.force_kobo_sync.dialog_title')"
:body-html="$t('dialog.force_kobo_sync.warning_html')"
:button-confirm="$t('common.i_understand')"
button-confirm-color="warning"
@confirm="deleteSyncPoint"
/>

<confirmation-dialog
v-model="modalDeleteApiKey"
:title="$t('dialog.delete_apikey.dialog_title')"
Expand Down Expand Up @@ -102,7 +122,9 @@ export default Vue.extend({
return {
apiKeys: [] as ApiKeyDto[],
apiKeyToDelete: {} as ApiKeyDto,
apiKeySyncPointsToDelete: {} as ApiKeyDto,
modalDeleteApiKey: false,
modalDeleteSyncPoints: false,
modalGenerateApiKey: false,
apiKeyLastActivity: {} as any,
}
Expand All @@ -128,6 +150,17 @@ export default Vue.extend({
this.apiKeyToDelete = apiKey
this.modalDeleteApiKey = true
},
promptSyncPointDelete(apiKey: ApiKeyDto) {
this.apiKeySyncPointsToDelete = apiKey
this.modalDeleteSyncPoints = true
},
async deleteSyncPoint() {
try {
await this.$komgaSyncPoints.deleteMySyncPointsByApiKey(this.apiKeySyncPointsToDelete.id)
} catch (e) {
this.$eventHub.$emit(ERROR, {message: e.message} as ErrorEvent)
}
},
async deleteApiKey() {
try {
await this.$komgaUsers.deleteApiKey(this.apiKeyToDelete.id)
Expand Down
10 changes: 8 additions & 2 deletions komga-webui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"api_key": {
"created_date": "Created date: {date}",
"generate_api_key": "Generate API key",
"no_keys": "No API Keys created yet"
"no_keys": "No API Keys created yet",
"force_kobo_sync": "Force Kobo sync"
},
"change_password": "change password"
},
Expand Down Expand Up @@ -260,7 +261,8 @@
"unlock_all": "Unlock all",
"url": "URL",
"use_filter_panel_to_change_filter": "Use the filter panel to change the active filter",
"year": "year"
"year": "year",
"i_understand": "I understand"
},
"dashboard": {
"keep_reading": "Keep Reading",
Expand Down Expand Up @@ -611,6 +613,10 @@
"page_of_pages": "{page} / {pages}",
"title": "Inspect Book",
"title_comparison": "Book Comparison"
},
"force_kobo_sync": {
"dialog_title": "Force Kobo sync",
"warning_html": "This will delete all sync history for this API key. Your Kobo will sync everything on the next sync."
}
},
"duplicate_pages": {
Expand Down
2 changes: 2 additions & 0 deletions komga-webui/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import komgaUsers from './plugins/komga-users.plugin'
import komgaTransientBooks from './plugins/komga-transientbooks.plugin'
import komgaSse from './plugins/komga-sse.plugin'
import komgaTasks from './plugins/komga-tasks.plugin'
import komgaSyncPoints from './plugins/komga-syncpoints.plugin'
import komgaOauth2 from './plugins/komga-oauth2.plugin'
import komgaLogin from './plugins/komga-login.plugin'
import komgaPageHashes from './plugins/komga-pagehashes.plugin'
Expand Down Expand Up @@ -69,6 +70,7 @@ Vue.use(komgaLibraries, {store: store, http: Vue.prototype.$http})
Vue.use(komgaSse, {eventHub: Vue.prototype.$eventHub, store: store})
Vue.use(actuator, {http: Vue.prototype.$http})
Vue.use(komgaTasks, {http: Vue.prototype.$http})
Vue.use(komgaSyncPoints, {http: Vue.prototype.$http})
Vue.use(komgaOauth2, {http: Vue.prototype.$http})
Vue.use(komgaLogin, {http: Vue.prototype.$http})
Vue.use(komgaPageHashes, {http: Vue.prototype.$http})
Expand Down
18 changes: 18 additions & 0 deletions komga-webui/src/plugins/komga-syncpoints.plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {AxiosInstance} from 'axios'
import _Vue from 'vue'
import KomgaTasksService from '@/services/komga-tasks.service'
import KomgaSyncPointsService from '@/services/komga-syncpoints.service'

export default {
install(
Vue: typeof _Vue,
{http}: { http: AxiosInstance }) {
Vue.prototype.$komgaSyncPoints = new KomgaSyncPointsService(http)
},
}

declare module 'vue/types/vue' {
interface Vue {
$komgaSyncPoints: KomgaSyncPointsService;
}
}
39 changes: 39 additions & 0 deletions komga-webui/src/services/komga-syncpoints.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {AxiosInstance} from 'axios'
import {
ApiKeyDto,
ApiKeyRequestDto,
AuthenticationActivityDto,
PasswordUpdateDto,
UserCreationDto,
UserDto,
UserUpdateDto,
} from '@/types/komga-users'

const qs = require('qs')

const API_SYNCPOINTS = '/api/v1/syncpoints'

export default class KomgaSyncPointsService {
private http: AxiosInstance

constructor(http: AxiosInstance) {
this.http = http
}

async deleteMySyncPointsByApiKey(apiKeyId: string) {
try {
console.log(`apikey: ${apiKeyId}`)

Check failure on line 25 in komga-webui/src/services/komga-syncpoints.service.ts

View workflow job for this annotation

GitHub Actions / Test webui builds

Unexpected console statement
await this.http.delete(`${API_SYNCPOINTS}/me`, {
params: {
key_id: apiKeyId,
},
})
} catch (e) {
let msg = `An error occurred while trying to delete syncpoints for apikey '${apiKeyId}'`
if (e.response.data.message) {
msg += `: ${e.response.data.message}`
}
throw new Error(msg)
}
}
}

0 comments on commit 8e5652f

Please sign in to comment.