Shoko.Server/API/v3/Controllers/FileController.cs
/// <summary>
/// Unlink all the episodes if no body is given, or only the spesified episodes from the file.
/// </summary>
/// <param name="fileID">The file id.</param>
/// <param name="body">Optional. The body.</param>
/// <returns></returns>
Unlink all the episodes if no body is given, or only the spesified episodes from the file.
Unlink all the episodes if no body is given or only the spesified episodes from the file .
[HttpDelete("{fileID}/Link")]
        public ActionResult UnlinkMultipleEpisodesFromFile([FromRoute] int fileID, [FromBody] File.Input.UnlinkEpisodesBody body)
        {
            var file = RepoFactory.VideoLocal.GetByID(fileID);
            if (file == null) return NotFound();
            var all = body == null;
            var episodeIdSet = body?.episodeIDs?.ToHashSet() ?? new();
            var seriesIDs = new HashSet<int>();
            foreach (var episode in file.GetAnimeEpisodes())
            {
                if (!all && !episodeIdSet.Contains(episode.AnimeEpisodeID)) continue;
                seriesIDs.Add(episode.AnimeSeriesID);
                var xref = RepoFactory.CrossRef_File_Episode.GetByHashAndEpisodeID(file.Hash, episode.AniDB_EpisodeID);
                if (xref != null)
                {
                    if (xref.CrossRefSource == (int) CrossRefSource.AniDB)
                        return BadRequest($"Cannot remove associations created from AniDB data for file '{file.VideoLocalID}'");
                    RepoFactory.CrossRef_File_Episode.Delete(xref.CrossRef_File_EpisodeID);
                }
            }
            foreach (var seriesID in seriesIDs) {
                var series = RepoFactory.AnimeSeries.GetByID(seriesID);
                if (series != null)
                    series.QueueUpdateStats();
            }
            return Ok();
        }
[ HttpDelete ( " " ) ] public ActionResult UnlinkMultipleEpisodesFromFile ( [ FromRoute ] int fileID , [ FromBody ] File . Input . UnlinkEpisodesBody body ) { var file = RepoFactory . VideoLocal . GetByID ( fileID ) ; if ( file == null ) return NotFound ( ) ; var all = body == null ; var episodeIdSet = body ? . episodeIDs ? . ToHashSet ( ) ?? new ( ) ; var seriesIDs = new HashSet < int > ( ) ; foreach ( var episode in file . GetAnimeEpisodes ( ) ) { if ( ! all && ! episodeIdSet . Contains ( episode . AnimeEpisodeID ) ) continue ; seriesIDs . Add ( episode . AnimeSeriesID ) ; var xref = RepoFactory . CrossRef_File_Episode . GetByHashAndEpisodeID ( file . Hash , episode . AniDB_EpisodeID ) ; if ( xref != null ) { if ( xref . CrossRefSource == ( int ) CrossRefSource . AniDB ) return BadRequest ( $" Cannot remove associations created from AniDB data for file ' { file . VideoLocalID } ' " ) ; RepoFactory . CrossRef_File_Episode . Delete ( xref . CrossRef_File_EpisodeID ) ; } } foreach ( var seriesID in seriesIDs ) { var series = RepoFactory . AnimeSeries . GetByID ( seriesID ) ; if ( series != null ) series . QueueUpdateStats ( ) ; } return Ok ( ) ; }
Unlink all the episodes if no body is given, or only the spesified episodes from the file.
Unlink all the episodes if no body is given or only the spesified episodes from the file .
None
int
[FromRoute]
File.Input.UnlinkEpisodesBody
[FromBody]
fileID
The file id.
The file id .
body
Optional. The body.
Optional . The body .