From 52fb1d97baa67137e3a9afadb2cc9ec2cfc04952 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 17 Jun 2021 11:09:54 +0200 Subject: Fix prune storage tests --- server/lib/activitypub/playlists/create-update.ts | 20 ++++++++++++-------- server/tests/cli/prune-storage.ts | 4 ++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/server/lib/activitypub/playlists/create-update.ts b/server/lib/activitypub/playlists/create-update.ts index dd4316d54..37d748de4 100644 --- a/server/lib/activitypub/playlists/create-update.ts +++ b/server/lib/activitypub/playlists/create-update.ts @@ -6,7 +6,7 @@ import { updatePlaylistMiniatureFromUrl } from '@server/lib/thumbnail' import { VideoPlaylistModel } from '@server/models/video/video-playlist' import { VideoPlaylistElementModel } from '@server/models/video/video-playlist-element' import { FilteredModelAttributes } from '@server/types' -import { MAccountDefault, MAccountId, MVideoPlaylist, MVideoPlaylistFull } from '@server/types/models' +import { MAccountDefault, MAccountId, MThumbnail, MVideoPlaylist, MVideoPlaylistFull } from '@server/types/models' import { AttributesOnly } from '@shared/core-utils' import { PlaylistObject } from '@shared/models' import { getOrCreateAPActor } from '../actors' @@ -54,11 +54,7 @@ async function createOrUpdateVideoPlaylist (playlistObject: PlaylistObject, byAc // Refetch playlist from DB since elements fetching could be long in time const playlist = await VideoPlaylistModel.loadWithAccountAndChannel(upsertPlaylist.id, null) - try { - await updatePlaylistThumbnail(playlistObject, playlist) - } catch (err) { - logger.warn('Cannot update thumbnail of %s.', playlistObject.id, { err, ...lTags(playlistObject.id, playlist.uuid, playlist.url) }) - } + await updatePlaylistThumbnail(playlistObject, playlist) return rebuildVideoPlaylistElements(playlistElementUrls, playlist) } @@ -98,8 +94,16 @@ async function fetchElementUrls (playlistObject: PlaylistObject) { async function updatePlaylistThumbnail (playlistObject: PlaylistObject, playlist: MVideoPlaylistFull) { if (playlistObject.icon) { - const thumbnailModel = await updatePlaylistMiniatureFromUrl({ downloadUrl: playlistObject.icon.url, playlist }) - await playlist.setAndSaveThumbnail(thumbnailModel, undefined) + let thumbnailModel: MThumbnail + + try { + thumbnailModel = await updatePlaylistMiniatureFromUrl({ downloadUrl: playlistObject.icon.url, playlist }) + await playlist.setAndSaveThumbnail(thumbnailModel, undefined) + } catch (err) { + logger.warn('Cannot set thumbnail of %s.', playlistObject.id, { err, ...lTags(playlistObject.id, playlist.uuid, playlist.url) }) + + if (thumbnailModel) await thumbnailModel.removeThumbnail() + } return } diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.ts index 591ed217f..5c9e023e1 100644 --- a/server/tests/cli/prune-storage.ts +++ b/server/tests/cli/prune-storage.ts @@ -12,6 +12,7 @@ import { flushAndRunMultipleServers, getAccount, getEnvCli, + killallServers, makeGetRequest, ServerInfo, setAccessTokensToServers, @@ -116,6 +117,9 @@ describe('Test prune storage scripts', function () { await wait(1000) await waitJobs(servers) + killallServers(servers) + + await wait(1000) }) it('Should have the files on the disk', async function () { -- cgit v1.2.3