Shoko.Server/API/v3/Controllers/FileController.cs
/// <summary>
/// Search for a file by path or name via regex. Internally, it will convert \/ to the system directory separator and match against the string
/// </summary>
/// <param name="path">a path to search for. URL Encoded</param>
/// <returns></returns>
Search for a file by path or name via regex. Internally, it will convert \/ to the system directory separator and match against the string
Search for a file by path or name via regex . Internally it will convert \ / to the system directory separator and match against the string
[HttpGet("PathRegex/{*path}")]
        public ActionResult<List<File.FileDetailed>> RegexSearchByFilename(string path)
        {
            var query = path;
            if (query.Contains("%") || query.Contains("+")) query = Uri.UnescapeDataString(query);
            if (query.Contains("%")) query = Uri.UnescapeDataString(query);
            if (Path.DirectorySeparatorChar == '\\') query = query.Replace("\\/", "\\\\");
            Regex regex;
            try
            {
                regex = new Regex(query, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
            }
            catch (RegexParseException e)
            {
                return BadRequest(e.Message);
            }
            var results = RepoFactory.VideoLocalPlace.GetAll().AsParallel()
                .Where(a => regex.IsMatch(a.FullServerPath)).Select(a => a.VideoLocal)
                .Distinct()
                .Where(a =>
                {
                    var ser = a?.GetAnimeEpisodes().FirstOrDefault()?.GetAnimeSeries();
                    return ser == null || User.AllowedSeries(ser);
                }).Select(a => new File.FileDetailed(HttpContext, a)).ToList();
            return results;
        }
[ HttpGet ( " " ) ] public ActionResult < List < File . FileDetailed > > RegexSearchByFilename ( string path ) { var query = path ; if ( query . Contains ( " " ) || query . Contains ( " " ) ) query = Uri . UnescapeDataString ( query ) ; if ( query . Contains ( " " ) ) query = Uri . UnescapeDataString ( query ) ; if ( Path . DirectorySeparatorChar == ' \\ ' ) query = query . Replace ( " \\ " , " \\ \\ " ) ; Regex regex ; try { regex = new Regex ( query , RegexOptions . CultureInvariant | RegexOptions . IgnoreCase ) ; } catch ( RegexParseException e ) { return BadRequest ( e . Message ) ; } var results = RepoFactory . VideoLocalPlace . GetAll ( ) . AsParallel ( ) . Where ( a => regex . IsMatch ( a . FullServerPath ) ) . Select ( a => a . VideoLocal ) . Distinct ( ) . Where ( a => { var ser = a ? . GetAnimeEpisodes ( ) . FirstOrDefault ( ) ? . GetAnimeSeries ( ) ; return ser == null || User . AllowedSeries ( ser ) ; } ) . Select ( a => new File . FileDetailed ( HttpContext , a ) ) . ToList ( ) ; return results ; }
Search for a file by path or name via regex.
Search for a file by path or name via regex .
None
path
string
a path to search for. URL Encoded
a path to search for . URL Encoded