import * as path from 'path';
import { UrlHelper } from './UrlHelper';
export class FilesHelper {
public static getUserDataFolder(): string {
let platform = process.platform;
let homepath: string;
Eif (platform.lastIndexOf('win') === 0) {
homepath = process.env.APPDATA || process.env.LOCALAPPDATA;
}
Iif (platform === 'darwin') {
homepath = process.env.HOME;
homepath = path.join(homepath, 'Library', 'Preferences');
}
Iif (platform === 'linux') {
homepath = process.env.HOME;
}
Iif (!homepath) {
throw new Error('Couldn\'t find the base application data folder');
}
return path.join(homepath, 'spauth');
}
public static resolveFileName(siteUrl: string): string {
let url = FilesHelper.resolveSiteUrl(siteUrl);
return url.replace(/[\:/\s]/g, '_');
}
private static resolveSiteUrl(siteUrl: string): string {
Eif (siteUrl.indexOf('/_') === -1 && siteUrl.indexOf('/vti_') === -1) {
return UrlHelper.removeTrailingSlash(siteUrl);
}
if (siteUrl.indexOf('/_') !== -1) {
return siteUrl.slice(0, siteUrl.indexOf('/_'));
}
if (siteUrl.indexOf('/vti_') !== -1) {
return siteUrl.slice(0, siteUrl.indexOf('/vti_'));
}
throw new Error('Unable to resolve web site url from full request url');
}
}
|