2023-02-22 15:12:53 +02:00
import { _ } from '../locale' ;
import Setting from '../models/Setting' ;
2023-05-29 13:20:56 +02:00
import { URL } from 'url' ;
const pathContainsUnsupportedProvider = ( path : string , unsupportedProviders : string [ ] ) = > {
try {
const url = new URL ( path . toLowerCase ( ) ) ;
const splitted = url . host . split ( '.' ) ;
for ( const s of splitted ) {
if ( unsupportedProviders . includes ( s ) ) return true ;
}
return false ;
} catch ( error ) {
// The URL is probably invalid, but it's not here that we should handle
// this.
return false ;
}
} ;
2023-02-22 15:12:53 +02:00
export const checkProviderIsSupported = ( path : string ) : void = > {
if ( Setting . value ( 'sync.allowUnsupportedProviders' ) === 1 ) return ;
2024-12-08 16:54:43 +02:00
const unsupportedProviders = [ 'jianguoyun' ] ;
2023-02-22 15:12:53 +02:00
for ( const p of unsupportedProviders ) {
2023-05-29 13:20:56 +02:00
if ( pathContainsUnsupportedProvider ( path , unsupportedProviders ) ) {
2023-02-22 15:12:53 +02:00
throw new Error ( _ ( 'The WebDAV implementation of %s is incompatible with Joplin, and as such is no longer supported. Please use a different sync method.' , p ) ) ;
}
}
} ;
export default checkProviderIsSupported ;