fix(import): on ne peux plus importer plusieurs fichiers sur le meme episodes, celui deja importé ce retire de l'importation dans le modal
fix(import): si on change un fichier son association alors il est bien retirer de l'import
This commit is contained in:
1 parent
a5e2aa0da1
commit
ad829c0a99
1 file changed
+40
-9
@@ -185,11 +185,12 @@ const serieTitle = computed(() =>
|
|||||||
const serieFolder = computed(() => `${props.initialPath}/${serieTitle.value}`)
|
const serieFolder = computed(() => `${props.initialPath}/${serieTitle.value}`)
|
||||||
|
|
||||||
interface FileItem {
|
interface FileItem {
|
||||||
file : { name: string; path: string; size: number }
|
file : { name: string; path: string; size: number }
|
||||||
episode_id : number | null
|
episode_id : number | null
|
||||||
hash : string | null
|
previousEpisodeId : number | null // ep_id original si alreadyImported et qu'on le réassigne
|
||||||
alreadyImported: boolean
|
hash : string | null
|
||||||
willRename : boolean
|
alreadyImported : boolean
|
||||||
|
willRename : boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const items = ref<FileItem[]>([])
|
const items = ref<FileItem[]>([])
|
||||||
@@ -266,8 +267,25 @@ function formatSize(bytes: number): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onEpisodeChange(i: number) {
|
function onEpisodeChange(i: number) {
|
||||||
items.value[i].hash = getHashForEpisode(Number(items.value[i].episode_id))
|
const item = items.value[i]
|
||||||
items.value[i].alreadyImported = false
|
const newEpId = item.episode_id
|
||||||
|
|
||||||
|
// Tracker l'ancien épisode pour pouvoir nettoyer l'entrée organized au moment de l'import
|
||||||
|
if (item.alreadyImported && item.episode_id !== newEpId) {
|
||||||
|
item.previousEpisodeId = item.episode_id
|
||||||
|
}
|
||||||
|
|
||||||
|
item.hash = getHashForEpisode(Number(newEpId))
|
||||||
|
item.alreadyImported = false
|
||||||
|
item.willRename = newEpId !== null
|
||||||
|
|
||||||
|
// Retirer les autres fichiers "déjà importés" pour ce même épisode :
|
||||||
|
// l'utilisateur a choisi de les remplacer par ce fichier-ci.
|
||||||
|
if (newEpId !== null) {
|
||||||
|
items.value = items.value.filter(other =>
|
||||||
|
other === item || !(other.episode_id === newEpId && other.alreadyImported)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Actions ──────────────────────────────────────────────────
|
// ─── Actions ──────────────────────────────────────────────────
|
||||||
@@ -292,11 +310,11 @@ async function scan() {
|
|||||||
// Vérifier si déjà importé via dest_path
|
// Vérifier si déjà importé via dest_path
|
||||||
const existingEpId = organizedByPath.get(f.path) ?? null
|
const existingEpId = organizedByPath.get(f.path) ?? null
|
||||||
if (existingEpId) {
|
if (existingEpId) {
|
||||||
return { file: f, episode_id: existingEpId, hash: getHashForEpisode(existingEpId), alreadyImported: true, willRename: false }
|
return { file: f, episode_id: existingEpId, previousEpisodeId: null, hash: getHashForEpisode(existingEpId), alreadyImported: true, willRename: false }
|
||||||
}
|
}
|
||||||
|
|
||||||
const match = autoMatch(f.name)
|
const match = autoMatch(f.name)
|
||||||
return { file: f, ...match, alreadyImported: false, willRename: match.episode_id !== null }
|
return { file: f, ...match, previousEpisodeId: null, alreadyImported: false, willRename: match.episode_id !== null }
|
||||||
})
|
})
|
||||||
} catch {
|
} catch {
|
||||||
scanError.value = 'Impossible de contacter le serveur'
|
scanError.value = 'Impossible de contacter le serveur'
|
||||||
@@ -319,6 +337,19 @@ async function doImport() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Nettoyer les anciens épisodes réassignés (fichier était "alreadyImported" ep A,
|
||||||
|
// l'utilisateur l'a changé en ep B → supprimer l'entrée organized de ep A sans toucher au fichier)
|
||||||
|
const toUnimport = items.value
|
||||||
|
.filter(i => i.previousEpisodeId !== null && i.episode_id !== i.previousEpisodeId)
|
||||||
|
.map(i => i.previousEpisodeId as number)
|
||||||
|
for (const oldEpId of toUnimport) {
|
||||||
|
try {
|
||||||
|
await fetch(`/api/organized/${props.serieId}/${oldEpId}?deleteFile=false`, {
|
||||||
|
method: 'DELETE', credentials: 'include',
|
||||||
|
})
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/manual-import', {
|
const res = await fetch('/api/manual-import', {
|
||||||
method : 'POST',
|
method : 'POST',
|
||||||
|
|||||||
Reference in new issue
Block a user