mirror of
https://github.com/gotson/komga.git
synced 2025-12-20 07:23:34 +01:00
feat: delete duplicate page match individually
This commit is contained in:
parent
a972b5fde0
commit
b53fbc7217
3 changed files with 65 additions and 5 deletions
|
|
@ -22,8 +22,18 @@
|
|||
/>
|
||||
</template>
|
||||
|
||||
<template v-slot:item.delete="{ item }">
|
||||
<v-btn
|
||||
icon
|
||||
color="error"
|
||||
@click="deleteMatch(item)"
|
||||
>
|
||||
<v-icon>mdi-trash-can-outline</v-icon>
|
||||
</v-btn>
|
||||
</template>
|
||||
|
||||
<template v-slot:footer.prepend>
|
||||
<v-btn icon @click="loadData">
|
||||
<v-btn icon @click="loadData(hash)">
|
||||
<v-icon>mdi-refresh</v-icon>
|
||||
</v-btn>
|
||||
</template>
|
||||
|
|
@ -33,7 +43,7 @@
|
|||
<script lang="ts">
|
||||
import Vue, {PropType} from 'vue'
|
||||
import {bookPageThumbnailUrl} from '@/functions/urls'
|
||||
import {PageHashDto, PageHashMatchDto, PageHashUnknownDto} from '@/types/komga-pagehashes'
|
||||
import {PageHashDto, PageHashMatchDto} from '@/types/komga-pagehashes'
|
||||
|
||||
export default Vue.extend({
|
||||
name: 'PageHashMatchesTable',
|
||||
|
|
@ -70,6 +80,7 @@ export default Vue.extend({
|
|||
{text: this.$t('common.filename').toString(), value: 'fileName'},
|
||||
{text: this.$t('common.page_number').toString(), value: 'pageNumber'},
|
||||
{text: this.$t('common.page').toString(), value: 'bookId'},
|
||||
{text: this.$t('menu.delete').toString(), value: 'delete'},
|
||||
]
|
||||
},
|
||||
},
|
||||
|
|
@ -95,6 +106,9 @@ export default Vue.extend({
|
|||
|
||||
this.loading = false
|
||||
},
|
||||
async deleteMatch(match: PageHashMatchDto) {
|
||||
await this.$komgaPageHashes.deleteSingleMatch(this.hash, match)
|
||||
},
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -82,18 +82,37 @@ export default class KomgaPageHashesService {
|
|||
}
|
||||
}
|
||||
|
||||
async deleteAllMatches(pageHash: PageHashKnownDto) {
|
||||
async deleteAllMatches(pageHash: PageHashDto) {
|
||||
try {
|
||||
const params = {
|
||||
media_type: pageHash.mediaType,
|
||||
file_size: pageHash.size || -1,
|
||||
}
|
||||
await this.http.post(`${API_PAGE_HASH}/${pageHash.hash}/delete-all`, pageHash, {
|
||||
await this.http.post(`${API_PAGE_HASH}/${pageHash.hash}/delete-all`, null, {
|
||||
params: params,
|
||||
paramsSerializer: params => qs.stringify(params, {indices: false}),
|
||||
})
|
||||
} catch (e) {
|
||||
let msg = `An error occurred while trying to execute perform-delete on page hash ${pageHash}`
|
||||
let msg = `An error occurred while trying to execute delete all matches on page hash ${pageHash}`
|
||||
if (e.response.data.message) {
|
||||
msg += `: ${e.response.data.message}`
|
||||
}
|
||||
throw new Error(msg)
|
||||
}
|
||||
}
|
||||
|
||||
async deleteSingleMatch(pageHash: PageHashDto, match: PageHashMatchDto) {
|
||||
try {
|
||||
const params = {
|
||||
media_type: pageHash.mediaType,
|
||||
file_size: pageHash.size || -1,
|
||||
}
|
||||
await this.http.post(`${API_PAGE_HASH}/${pageHash.hash}/delete-match`, match, {
|
||||
params: params,
|
||||
paramsSerializer: params => qs.stringify(params, {indices: false}),
|
||||
})
|
||||
} catch (e) {
|
||||
let msg = `An error occurred while trying to execute delete single match on page hash ${pageHash}`
|
||||
if (e.response.data.message) {
|
||||
msg += `: ${e.response.data.message}`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,4 +146,31 @@ class PageHashController(
|
|||
|
||||
toRemove.forEach { taskReceiver.removeDuplicatePages(it.key, it.value) }
|
||||
}
|
||||
|
||||
@PostMapping("{pageHash}/delete-match")
|
||||
@ResponseStatus(HttpStatus.ACCEPTED)
|
||||
fun deleteSingleMatch(
|
||||
@PathVariable pageHash: String,
|
||||
@RequestParam("media_type") mediaType: String,
|
||||
@RequestParam("file_size") size: Long,
|
||||
@RequestBody matchDto: PageHashMatchDto,
|
||||
) {
|
||||
val hash = pageHashRepository.findKnown(PageHash(pageHash, mediaType, size))
|
||||
?: throw ResponseStatusException(HttpStatus.NOT_FOUND)
|
||||
|
||||
val toRemove = Pair(
|
||||
matchDto.bookId,
|
||||
listOf(
|
||||
BookPageNumbered(
|
||||
fileName = matchDto.fileName,
|
||||
mediaType = hash.mediaType,
|
||||
fileHash = hash.hash,
|
||||
fileSize = hash.size,
|
||||
pageNumber = matchDto.pageNumber,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
taskReceiver.removeDuplicatePages(toRemove.first, toRemove.second)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue