import { FileRef } from "polar-shared/src/datastore/FileRef" ; import { Preconditions } from "polar-shared/src/Preconditions" ; export class DatastoreFiles { /**
     * Make sure the file name is sane ... nothing that can't be encoded
     * as a file and must have a three letter extension.  We should just have
     * the files be alphanumeric for now and support a 3-4 char suffix.
     */ public static isValidFileName ( name ) { return name . search ( /^[a-zA-Z0-9_(),{} -]+(\.[a-zA-Z0-9]{3,4})?$/g ) !== - 1 ; } public static assertValidFileName ( ref ) { if ( ! this . isValidFileName ( ref . name ) ) { throw new Error ( "Invalid file name: " + ref . name ) ; } } param name public static sanitizeFileName ( name ) { return name . replace ( /[/\\:*?\"<>|]/g , '_' ) ; } public static isSanitizedFileName ( name ) { Preconditions . assertPresent ( name , "name" ) ; return name . search ( /[/\\:*?\"<>|]/ ) === - 1 ; } public static assertSanitizedFileName ( ref ) { if ( ! this . isSanitizedFileName ( ref . name ) ) { throw new Error ( "Invalid file name: " + ref . name ) ; } } }