MOBILE-3657 file: Add helper function to get filename from path
parent
8fda3f39f2
commit
8d31beb0a7
|
@ -33,6 +33,7 @@ import { AddonModAssignSubmissionFormatted } from './assign-helper';
|
|||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { AddonModAssignAutoSyncData, AddonModAssignManualSyncData, AddonModAssignSyncProvider } from './assign-sync';
|
||||
import { CoreFormFields } from '@singletons/form';
|
||||
import { CoreFileHelper } from '@services/file-helper';
|
||||
|
||||
const ROOT_CACHE_KEY = 'mmaModAssign:';
|
||||
|
||||
|
@ -420,7 +421,7 @@ export class AddonModAssignProvider {
|
|||
filearea.files.forEach((file) => {
|
||||
if (!file.filename) {
|
||||
// We don't have filename, extract it from the path.
|
||||
file.filename = file.filepath?.charAt(0) == '/' ? file.filepath.substr(1) : file.filepath;
|
||||
file.filename = CoreFileHelper.getFilenameFromPath(file);
|
||||
}
|
||||
|
||||
files.push(file);
|
||||
|
|
|
@ -417,6 +417,22 @@ export class CoreFileHelperProvider {
|
|||
return !!fileTypeExcludeList.match(regEx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract filename from the path.
|
||||
*
|
||||
* @param file The file.
|
||||
* @return The file name.
|
||||
*/
|
||||
getFilenameFromPath(file: CoreFileEntry): string | undefined {
|
||||
const path = CoreUtils.isFileEntry(file) ? file.fullPath : file.filepath;
|
||||
|
||||
if (typeof path == 'undefined' || path.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
return path.split('\\').pop()?.split('/').pop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const CoreFileHelper = makeSingleton(CoreFileHelperProvider);
|
||||
|
|
|
@ -1390,7 +1390,7 @@ export class CoreDomUtilsProvider {
|
|||
async showErrorModalDefault(
|
||||
error: CoreAnyError,
|
||||
defaultError: string,
|
||||
needsTranslate?: boolean,
|
||||
needsTranslate = false,
|
||||
autocloseTime?: number,
|
||||
): Promise<HTMLIonAlertElement | null> {
|
||||
if (this.isCanceledError(error)) {
|
||||
|
|
Loading…
Reference in New Issue