diff --git a/src/addons/blog/services/handlers/course-option.ts b/src/addons/blog/services/handlers/course-option.ts index 7b6f241e4..c15f4b4de 100644 --- a/src/addons/blog/services/handlers/course-option.ts +++ b/src/addons/blog/services/handlers/course-option.ts @@ -24,7 +24,7 @@ import { CoreCourseUserAdminOrNavOptionIndexed } from '@features/courses/service import { CoreEnrolledCourseDataWithExtraInfoAndOptions } from '@features/courses/services/courses-helper'; import { CoreFilepool } from '@services/filepool'; import { CoreSites } from '@services/sites'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonBlog } from '../blog'; import { AddonBlogMainMenuHandlerService } from './mainmenu'; @@ -89,7 +89,7 @@ export class AddonBlogCourseOptionHandlerService implements CoreCourseOptionsHan const result = await AddonBlog.getEntries({ courseid: course.id }); await Promise.all(result.entries.map(async (entry) => { - let files: CoreWSExternalFile[] = []; + let files: CoreWSFile[] = []; if (entry.attachmentfiles && entry.attachmentfiles.length) { files = entry.attachmentfiles; diff --git a/src/addons/mod/assign/components/feedback-plugin/feedback-plugin.ts b/src/addons/mod/assign/components/feedback-plugin/feedback-plugin.ts index 39eae9e4f..ed4f46182 100644 --- a/src/addons/mod/assign/components/feedback-plugin/feedback-plugin.ts +++ b/src/addons/mod/assign/components/feedback-plugin/feedback-plugin.ts @@ -15,7 +15,7 @@ import { Component, Input, OnInit, ViewChild, Type } from '@angular/core'; import { CoreError } from '@classes/errors/error'; import { CoreDynamicComponent } from '@components/dynamic-component/dynamic-component'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { ModalController } from '@singletons'; import { AddonModAssignFeedbackCommentsTextData } from '../../feedback/comments/services/handler'; import { @@ -53,7 +53,7 @@ export class AddonModAssignFeedbackPluginComponent implements OnInit { // Data to render the plugin if it isn't supported. component = AddonModAssignProvider.COMPONENT; text = ''; - files: CoreWSExternalFile[] = []; + files: CoreWSFile[] = []; notSupported = false; pluginLoaded = false; diff --git a/src/addons/mod/assign/components/submission-plugin/submission-plugin.ts b/src/addons/mod/assign/components/submission-plugin/submission-plugin.ts index c54e39cdb..7fda5c4ba 100644 --- a/src/addons/mod/assign/components/submission-plugin/submission-plugin.ts +++ b/src/addons/mod/assign/components/submission-plugin/submission-plugin.ts @@ -14,7 +14,6 @@ import { Component, Input, OnInit, Type, ViewChild } from '@angular/core'; import { CoreDynamicComponent } from '@components/dynamic-component/dynamic-component'; -import { CoreWSExternalFile } from '@services/ws'; import { AddonModAssignAssign, AddonModAssignSubmission, @@ -24,7 +23,7 @@ import { } from '../../services/assign'; import { AddonModAssignHelper, AddonModAssignPluginConfig } from '../../services/assign-helper'; import { AddonModAssignSubmissionDelegate } from '../../services/submission-delegate'; -import { FileEntry } from '@ionic-native/file/ngx'; +import { CoreFileEntry } from '@services/file-helper'; /** * Component that displays an assignment submission plugin. @@ -49,7 +48,7 @@ export class AddonModAssignSubmissionPluginComponent implements OnInit { // Data to render the plugin if it isn't supported. component = AddonModAssignProvider.COMPONENT; text = ''; - files: (FileEntry | CoreWSExternalFile)[] = []; + files: CoreFileEntry[] = []; notSupported = false; pluginLoaded = false; diff --git a/src/addons/mod/assign/feedback/comments/services/handler.ts b/src/addons/mod/assign/feedback/comments/services/handler.ts index c952f961c..0e0a3b4ce 100644 --- a/src/addons/mod/assign/feedback/comments/services/handler.ts +++ b/src/addons/mod/assign/feedback/comments/services/handler.ts @@ -25,7 +25,7 @@ import { Injectable, Type } from '@angular/core'; import { CoreSites } from '@services/sites'; import { CoreTextUtils } from '@services/utils/text'; import { CoreUtils } from '@services/utils/utils'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonModAssignFeedbackCommentsComponent } from '../component/comments'; @@ -126,7 +126,7 @@ export class AddonModAssignFeedbackCommentsHandlerService implements AddonModAss assign: AddonModAssignAssign, submission: AddonModAssignSubmission, plugin: AddonModAssignPlugin, - ): CoreWSExternalFile[] { + ): CoreWSFile[] { return AddonModAssign.getSubmissionPluginAttachments(plugin); } diff --git a/src/addons/mod/assign/feedback/editpdf/component/editpdf.ts b/src/addons/mod/assign/feedback/editpdf/component/editpdf.ts index df1ff86ea..733aa8d47 100644 --- a/src/addons/mod/assign/feedback/editpdf/component/editpdf.ts +++ b/src/addons/mod/assign/feedback/editpdf/component/editpdf.ts @@ -15,7 +15,7 @@ import { AddonModAssignFeedbackPluginComponent } from '@addons/mod/assign/components/feedback-plugin/feedback-plugin'; import { AddonModAssignProvider, AddonModAssign } from '@addons/mod/assign/services/assign'; import { Component, OnInit } from '@angular/core'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; /** * Component to render a edit pdf feedback plugin. @@ -27,7 +27,7 @@ import { CoreWSExternalFile } from '@services/ws'; export class AddonModAssignFeedbackEditPdfComponent extends AddonModAssignFeedbackPluginComponent implements OnInit { component = AddonModAssignProvider.COMPONENT; - files: CoreWSExternalFile[] = []; + files: CoreWSFile[] = []; /** * Component being initialized. diff --git a/src/addons/mod/assign/feedback/editpdf/services/handler.ts b/src/addons/mod/assign/feedback/editpdf/services/handler.ts index dc9cb02d7..d3fac5247 100644 --- a/src/addons/mod/assign/feedback/editpdf/services/handler.ts +++ b/src/addons/mod/assign/feedback/editpdf/services/handler.ts @@ -20,7 +20,7 @@ import { } from '@addons/mod/assign/services/assign'; import { AddonModAssignFeedbackHandler } from '@addons/mod/assign/services/feedback-delegate'; import { Injectable, Type } from '@angular/core'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonModAssignFeedbackEditPdfComponent } from '../component/editpdf'; @@ -56,7 +56,7 @@ export class AddonModAssignFeedbackEditPdfHandlerService implements AddonModAssi assign: AddonModAssignAssign, submission: AddonModAssignSubmission, plugin: AddonModAssignPlugin, - ): CoreWSExternalFile[] { + ): CoreWSFile[] { return AddonModAssign.getSubmissionPluginAttachments(plugin); } diff --git a/src/addons/mod/assign/feedback/file/component/file.ts b/src/addons/mod/assign/feedback/file/component/file.ts index 64d2af54f..c407baf9d 100644 --- a/src/addons/mod/assign/feedback/file/component/file.ts +++ b/src/addons/mod/assign/feedback/file/component/file.ts @@ -15,7 +15,7 @@ import { AddonModAssignFeedbackPluginComponent } from '@addons/mod/assign/components/feedback-plugin/feedback-plugin'; import { AddonModAssign, AddonModAssignProvider } from '@addons/mod/assign/services/assign'; import { Component, OnInit } from '@angular/core'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; /** * Component to render a file feedback plugin. @@ -27,7 +27,7 @@ import { CoreWSExternalFile } from '@services/ws'; export class AddonModAssignFeedbackFileComponent extends AddonModAssignFeedbackPluginComponent implements OnInit { component = AddonModAssignProvider.COMPONENT; - files: CoreWSExternalFile[] = []; + files: CoreWSFile[] = []; /** * Component being initialized. diff --git a/src/addons/mod/assign/feedback/file/services/handler.ts b/src/addons/mod/assign/feedback/file/services/handler.ts index d8854bb13..d77d7991c 100644 --- a/src/addons/mod/assign/feedback/file/services/handler.ts +++ b/src/addons/mod/assign/feedback/file/services/handler.ts @@ -20,7 +20,7 @@ import { } from '@addons/mod/assign/services/assign'; import { AddonModAssignFeedbackHandler } from '@addons/mod/assign/services/feedback-delegate'; import { Injectable, Type } from '@angular/core'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonModAssignFeedbackFileComponent } from '../component/file'; @@ -56,7 +56,7 @@ export class AddonModAssignFeedbackFileHandlerService implements AddonModAssignF assign: AddonModAssignAssign, submission: AddonModAssignSubmission, plugin: AddonModAssignPlugin, - ): CoreWSExternalFile[] { + ): CoreWSFile[] { return AddonModAssign.getSubmissionPluginAttachments(plugin); } diff --git a/src/addons/mod/assign/services/assign-helper.ts b/src/addons/mod/assign/services/assign-helper.ts index b4bbb4eb7..2da29183c 100644 --- a/src/addons/mod/assign/services/assign-helper.ts +++ b/src/addons/mod/assign/services/assign-helper.ts @@ -15,7 +15,6 @@ import { Injectable } from '@angular/core'; import { CoreFileUploader, CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader'; import { CoreSites, CoreSitesCommonWSOptions } from '@services/sites'; -import { CoreWSExternalFile } from '@services/ws'; import { FileEntry } from '@ionic-native/file/ngx'; import { AddonModAssignProvider, @@ -36,6 +35,7 @@ import { AddonModAssignSubmissionDelegate } from './submission-delegate'; import { AddonModAssignFeedbackDelegate } from './feedback-delegate'; import { makeSingleton } from '@singletons'; import { CoreFormFields } from '@singletons/form'; +import { CoreFileEntry } from '@services/file-helper'; /** * Service that provides some helper functions for assign. @@ -642,7 +642,7 @@ export class AddonModAssignHelperProvider { async storeSubmissionFiles( assignId: number, folderName: string, - files: (CoreWSExternalFile | FileEntry)[], + files: CoreFileEntry[], userId?: number, siteId?: string, ): Promise { @@ -661,7 +661,7 @@ export class AddonModAssignHelperProvider { * @param siteId Site ID. If not defined, current site. * @return Promise resolved with the itemId. */ - uploadFile(assignId: number, file: CoreWSExternalFile | FileEntry, itemId?: number, siteId?: string): Promise { + uploadFile(assignId: number, file: CoreFileEntry, itemId?: number, siteId?: string): Promise { return CoreFileUploader.uploadOrReuploadFile(file, itemId, AddonModAssignProvider.COMPONENT, assignId, siteId); } @@ -675,7 +675,7 @@ export class AddonModAssignHelperProvider { * @param siteId Site ID. If not defined, current site. * @return Promise resolved with the itemId. */ - uploadFiles(assignId: number, files: (CoreWSExternalFile | FileEntry)[], siteId?: string): Promise { + uploadFiles(assignId: number, files: CoreFileEntry[], siteId?: string): Promise { return CoreFileUploader.uploadOrReuploadFiles(files, AddonModAssignProvider.COMPONENT, assignId, siteId); } @@ -693,7 +693,7 @@ export class AddonModAssignHelperProvider { async uploadOrStoreFiles( assignId: number, folderName: string, - files: (CoreWSExternalFile | FileEntry)[], + files: CoreFileEntry[], offline = false, userId?: number, siteId?: string, diff --git a/src/addons/mod/assign/services/assign-sync.ts b/src/addons/mod/assign/services/assign-sync.ts index 2ea3fd466..60cad1218 100644 --- a/src/addons/mod/assign/services/assign-sync.ts +++ b/src/addons/mod/assign/services/assign-sync.ts @@ -53,7 +53,7 @@ export class AddonModAssignSyncProvider extends CoreCourseActivitySyncBaseProvid protected componentTranslatableString = 'assign'; constructor() { - super('AddonModLessonSyncProvider'); + super('AddonModAssignSyncProvider'); } /** diff --git a/src/addons/mod/assign/services/assign.ts b/src/addons/mod/assign/services/assign.ts index aa53f5f4f..dec89da07 100644 --- a/src/addons/mod/assign/services/assign.ts +++ b/src/addons/mod/assign/services/assign.ts @@ -16,7 +16,7 @@ import { Injectable } from '@angular/core'; import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; import { CoreInterceptor } from '@classes/interceptor'; -import { CoreWSExternalWarning, CoreWSExternalFile } from '@services/ws'; +import { CoreWSExternalWarning, CoreWSExternalFile, CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { CoreTextUtils } from '@services/utils/text'; @@ -405,12 +405,12 @@ export class AddonModAssignProvider { * @param submissionPlugin Submission plugin. * @return Submission plugin attachments. */ - getSubmissionPluginAttachments(submissionPlugin: AddonModAssignPlugin): CoreWSExternalFile[] { + getSubmissionPluginAttachments(submissionPlugin: AddonModAssignPlugin): CoreWSFile[] { if (!submissionPlugin.fileareas) { return []; } - const files: CoreWSExternalFile[] = []; + const files: CoreWSFile[] = []; submissionPlugin.fileareas.forEach((filearea) => { if (!filearea || !filearea.files) { diff --git a/src/addons/mod/assign/services/feedback-delegate.ts b/src/addons/mod/assign/services/feedback-delegate.ts index 8c9951877..2fb96a013 100644 --- a/src/addons/mod/assign/services/feedback-delegate.ts +++ b/src/addons/mod/assign/services/feedback-delegate.ts @@ -17,7 +17,7 @@ import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate'; import { AddonModAssignDefaultFeedbackHandler } from './handlers/default-feedback'; import { AddonModAssignAssign, AddonModAssignSubmission, AddonModAssignPlugin, AddonModAssignSavePluginData } from './assign'; import { makeSingleton } from '@singletons'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { AddonModAssignSubmissionFormatted } from './assign-helper'; import { CoreFormFields } from '@singletons/form'; @@ -79,7 +79,7 @@ export interface AddonModAssignFeedbackHandler extends CoreDelegateHandler { submission: AddonModAssignSubmission, plugin: AddonModAssignPlugin, siteId?: string, - ): CoreWSExternalFile[] | Promise; + ): CoreWSFile[] | Promise; /** * Get a readable name to use for the plugin. @@ -246,8 +246,8 @@ export class AddonModAssignFeedbackDelegateService extends CoreDelegate { - const files: CoreWSExternalFile[] | undefined = + ): Promise { + const files: CoreWSFile[] | undefined = await this.executeFunctionOnEnabled(plugin.type, 'getPluginFiles', [assign, submission, plugin, siteId]); return files || []; diff --git a/src/addons/mod/assign/services/handlers/default-feedback.ts b/src/addons/mod/assign/services/handlers/default-feedback.ts index 62c394bdb..ef19ffdd7 100644 --- a/src/addons/mod/assign/services/handlers/default-feedback.ts +++ b/src/addons/mod/assign/services/handlers/default-feedback.ts @@ -13,7 +13,7 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { Translate } from '@singletons'; import { AddonModAssignPlugin } from '../assign'; import { AddonModAssignFeedbackHandler } from '../feedback-delegate'; @@ -52,7 +52,7 @@ export class AddonModAssignDefaultFeedbackHandler implements AddonModAssignFeedb * * @return The files (or promise resolved with the files). */ - getPluginFiles(): CoreWSExternalFile[] { + getPluginFiles(): CoreWSFile[] { return []; } diff --git a/src/addons/mod/assign/services/handlers/default-submission.ts b/src/addons/mod/assign/services/handlers/default-submission.ts index db3791205..2d2b42cf0 100644 --- a/src/addons/mod/assign/services/handlers/default-submission.ts +++ b/src/addons/mod/assign/services/handlers/default-submission.ts @@ -13,7 +13,7 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { Translate } from '@singletons'; import { AddonModAssignPlugin } from '../assign'; import { AddonModAssignSubmissionHandler } from '../submission-delegate'; @@ -79,7 +79,7 @@ export class AddonModAssignDefaultSubmissionHandler implements AddonModAssignSub * * @return The files (or promise resolved with the files). */ - getPluginFiles(): CoreWSExternalFile[] { + getPluginFiles(): CoreWSFile[] { return []; } diff --git a/src/addons/mod/assign/services/handlers/prefetch.ts b/src/addons/mod/assign/services/handlers/prefetch.ts index f2f092d28..0ffc75535 100644 --- a/src/addons/mod/assign/services/handlers/prefetch.ts +++ b/src/addons/mod/assign/services/handlers/prefetch.ts @@ -26,7 +26,7 @@ import { AddonModAssignSubmissionDelegate } from '../submission-delegate'; import { AddonModAssignFeedbackDelegate } from '../feedback-delegate'; import { CoreCourseActivityPrefetchHandlerBase } from '@features/course/classes/activity-prefetch-handler'; import { CoreCourse, CoreCourseAnyModuleData, CoreCourseCommonModWSOptions } from '@features/course/services/course'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { AddonModAssignHelper, AddonModAssignSubmissionFormatted } from '../assign-helper'; import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreUtils } from '@services/utils/utils'; @@ -82,13 +82,13 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref * @param courseId Course ID the module belongs to. * @return Promise resolved with the list of files. */ - async getFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { + async getFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { const siteId = CoreSites.getCurrentSiteId(); try { const assign = await AddonModAssign.getAssignment(courseId, module.id, { siteId }); // Get intro files and attachments. - let files = assign.introattachments || []; + let files: CoreWSFile[] = assign.introattachments || []; files = files.concat(this.getIntroFilesFromInstance(module, assign)); // Now get the files in the submissions. @@ -145,7 +145,7 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref submitId: number, blindMarking: boolean, siteId?: string, - ): Promise { + ): Promise { const submissionStatus = await AddonModAssign.getSubmissionStatusWithRetry(assign, { userId: submitId, @@ -158,7 +158,7 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref return []; } - const promises: Promise[] = []; + const promises: Promise[] = []; if (userSubmission.plugins) { // Add submission plugin files. @@ -245,7 +245,7 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref // Get assignment to retrieve all its submissions. const assign = await AddonModAssign.getAssignment(courseId, module.id, options); - const promises: Promise[] = []; + const promises: Promise[] = []; const blindMarking = assign.blindmarking && !assign.revealidentities; if (blindMarking) { @@ -259,7 +259,7 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref promises.push(CoreCourseHelper.getModuleCourseIdByInstance(assign.id, 'assign', siteId)); // Download intro files and attachments. Do not call getFiles because it'd call some WS twice. - let files = assign.introattachments || []; + let files: CoreWSFile[] = assign.introattachments || []; files = files.concat(this.getIntroFilesFromInstance(module, assign)); promises.push(CoreFilepool.addFilesToQueue(siteId, files, this.component, module.id)); @@ -293,7 +293,7 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref // Get submissions. const submissions = await AddonModAssign.getSubmissions(assign.id, modOptions); - const promises: Promise[] = []; + const promises: Promise[] = []; promises.push(this.prefetchParticipantSubmissions( assign, @@ -359,7 +359,7 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref AddonModAssignHelper.getSubmissionsUserData(assign, submissions, group.id, options) .then((submissions: AddonModAssignSubmissionFormatted[]) => { - const subPromises: Promise[] = submissions.map((submission) => { + const subPromises: Promise[] = submissions.map((submission) => { const submissionOptions = { userId: submission.submitid, groupId: group.id, @@ -426,7 +426,7 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref const userId = options.userId; try { - const promises: Promise[] = []; + const promises: Promise[] = []; const blindMarking = !!assign.blindmarking && !assign.revealidentities; let userIds: number[] = []; const userSubmission = AddonModAssign.getSubmissionObjectFromAttempt(assign, submission.lastattempt); diff --git a/src/addons/mod/assign/services/submission-delegate.ts b/src/addons/mod/assign/services/submission-delegate.ts index a58da6eac..136da9d78 100644 --- a/src/addons/mod/assign/services/submission-delegate.ts +++ b/src/addons/mod/assign/services/submission-delegate.ts @@ -17,7 +17,7 @@ import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate'; import { AddonModAssignDefaultSubmissionHandler } from './handlers/default-submission'; import { AddonModAssignAssign, AddonModAssignSubmission, AddonModAssignPlugin, AddonModAssignSavePluginData } from './assign'; import { makeSingleton } from '@singletons'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { AddonModAssignSubmissionsDBRecordFormatted } from './assign-offline'; import { CoreFormFields } from '@singletons/form'; @@ -139,7 +139,7 @@ export interface AddonModAssignSubmissionHandler extends CoreDelegateHandler { submission: AddonModAssignSubmission, plugin: AddonModAssignPlugin, siteId?: string, - ): CoreWSExternalFile[] | Promise; + ): CoreWSFile[] | Promise; /** * Get a readable name to use for the plugin. @@ -384,8 +384,8 @@ export class AddonModAssignSubmissionDelegateService extends CoreDelegate { - const files: CoreWSExternalFile[] | undefined = + ): Promise { + const files: CoreWSFile[] | undefined = await this.executeFunctionOnEnabled(plugin.type, 'getPluginFiles', [assign, submission, plugin, siteId]); return files || []; diff --git a/src/addons/mod/assign/submission/file/services/handler.ts b/src/addons/mod/assign/submission/file/services/handler.ts index 00333791c..72c93d843 100644 --- a/src/addons/mod/assign/submission/file/services/handler.ts +++ b/src/addons/mod/assign/submission/file/services/handler.ts @@ -24,10 +24,10 @@ import { AddonModAssignOffline, AddonModAssignSubmissionsDBRecordFormatted } fro import { AddonModAssignSubmissionHandler } from '@addons/mod/assign/services/submission-delegate'; import { Injectable, Type } from '@angular/core'; import { CoreFileUploader, CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader'; -import { CoreFileHelper } from '@services/file-helper'; +import { CoreFileEntry, CoreFileHelper } from '@services/file-helper'; import { CoreFileSession } from '@services/file-session'; import { CoreUtils } from '@services/utils/utils'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonModAssignSubmissionFileComponent } from '../component/file'; import { FileEntry } from '@ionic-native/file/ngx'; @@ -156,7 +156,7 @@ export class AddonModAssignSubmissionFileHandlerService implements AddonModAssig assign: AddonModAssignAssign, submission: AddonModAssignSubmission, plugin: AddonModAssignPlugin, - ): CoreWSExternalFile[] { + ): CoreWSFile[] { return AddonModAssign.getSubmissionPluginAttachments(plugin); } @@ -350,14 +350,14 @@ export class AddonModAssignSubmissionFileHandlerService implements AddonModAssig submission: AddonModAssignSubmission, offlineData?: AddonModAssignSubmissionsDBRecordFormatted, siteId?: string, - ): Promise<(FileEntry | CoreWSExternalFile)[]> { + ): Promise { const filesData = offlineData?.plugindata.files_filemanager; if (!filesData) { return []; } // Has some data to sync. - let files: (FileEntry | CoreWSExternalFile)[] = filesData.online || []; + let files: CoreFileEntry[] = filesData.online || []; if (filesData.offline) { // Has offline files, get them and add them to the list. diff --git a/src/addons/mod/assign/submission/onlinetext/services/handler.ts b/src/addons/mod/assign/submission/onlinetext/services/handler.ts index 36e4c04c5..56f86d63a 100644 --- a/src/addons/mod/assign/submission/onlinetext/services/handler.ts +++ b/src/addons/mod/assign/submission/onlinetext/services/handler.ts @@ -27,7 +27,7 @@ import { CoreFileHelper } from '@services/file-helper'; import { CoreSites } from '@services/sites'; import { CoreTextUtils } from '@services/utils/text'; import { CoreUtils } from '@services/utils/utils'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { makeSingleton, Translate } from '@singletons'; import { AddonModAssignSubmissionOnlineTextComponent } from '../component/onlinetext'; @@ -124,7 +124,7 @@ export class AddonModAssignSubmissionOnlineTextHandlerService implements AddonMo assign: AddonModAssignAssign, submission: AddonModAssignSubmission, plugin: AddonModAssignPlugin, - ): CoreWSExternalFile[] { + ): CoreWSFile[] { return AddonModAssign.getSubmissionPluginAttachments(plugin); } diff --git a/src/addons/mod/book/services/handlers/prefetch.ts b/src/addons/mod/book/services/handlers/prefetch.ts index 6dc9c26cf..75dff4a32 100644 --- a/src/addons/mod/book/services/handlers/prefetch.ts +++ b/src/addons/mod/book/services/handlers/prefetch.ts @@ -16,7 +16,7 @@ import { Injectable } from '@angular/core'; import { CoreCourseResourcePrefetchHandlerBase } from '@features/course/classes/resource-prefetch-handler'; import { CoreCourseAnyModuleData, CoreCourseWSModule } from '@features/course/services/course'; import { CoreUtils } from '@services/utils/utils'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonModBook, AddonModBookProvider } from '../book'; @@ -55,7 +55,7 @@ export class AddonModBookPrefetchHandlerService extends CoreCourseResourcePrefet * @param courseId Course ID. * @return Promise resolved with list of intro files. */ - async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { + async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { const book = await CoreUtils.ignoreErrors(AddonModBook.getBook(courseId, module.id)); return this.getIntroFilesFromInstance(module, book); diff --git a/src/addons/mod/choice/services/handlers/prefetch.ts b/src/addons/mod/choice/services/handlers/prefetch.ts index 0ead84f9a..d8e10a54a 100644 --- a/src/addons/mod/choice/services/handlers/prefetch.ts +++ b/src/addons/mod/choice/services/handlers/prefetch.ts @@ -19,7 +19,7 @@ import { CoreUser } from '@features/user/services/user'; import { CoreFilepool } from '@services/filepool'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonModChoice, AddonModChoiceProvider } from '../choice'; import { AddonModChoiceSync, AddonModChoiceSyncResult } from '../choice-sync'; @@ -116,7 +116,7 @@ export class AddonModChoicePrefetchHandlerService extends CoreCourseActivityPref /** * @inheritdoc */ - async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { + async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { const choice = await CoreUtils.ignoreErrors(AddonModChoice.getChoice(courseId, module.id)); return this.getIntroFilesFromInstance(module, choice); diff --git a/src/addons/mod/data/fields/file/component/file.ts b/src/addons/mod/data/fields/file/component/file.ts index 2f1680027..542858939 100644 --- a/src/addons/mod/data/fields/file/component/file.ts +++ b/src/addons/mod/data/fields/file/component/file.ts @@ -15,8 +15,7 @@ import { Component } from '@angular/core'; import { AddonModDataEntryField, AddonModDataProvider } from '@addons/mod/data/services/data'; import { AddonModDataFieldPluginComponent } from '@addons/mod/data/classes/field-plugin-component'; import { CoreFileSession } from '@services/file-session'; -import { CoreWSExternalFile } from '@services/ws'; -import { FileEntry } from '@ionic-native/file'; +import { CoreFileEntry } from '@services/file-helper'; /** * Component to render data file field. @@ -27,7 +26,7 @@ import { FileEntry } from '@ionic-native/file'; }) export class AddonModDataFieldFileComponent extends AddonModDataFieldPluginComponent { - files: (CoreWSExternalFile | FileEntry)[] = []; + files: CoreFileEntry[] = []; component?: string; componentId?: number; maxSizeBytes?: number; @@ -38,7 +37,7 @@ export class AddonModDataFieldFileComponent extends AddonModDataFieldPluginCompo * @param value Input value. * @return List of files. */ - protected getFiles(value?: Partial): (CoreWSExternalFile | FileEntry)[] { + protected getFiles(value?: Partial): CoreFileEntry[] { let files = value?.files || []; // Reduce to first element. diff --git a/src/addons/mod/data/fields/file/services/handler.ts b/src/addons/mod/data/fields/file/services/handler.ts index 77157c31e..2db49d5c3 100644 --- a/src/addons/mod/data/fields/file/services/handler.ts +++ b/src/addons/mod/data/fields/file/services/handler.ts @@ -22,12 +22,12 @@ import { import { AddonModDataFieldHandler } from '@addons/mod/data/services/data-fields-delegate'; import { Injectable, Type } from '@angular/core'; import { CoreFileUploader, CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader'; -import { FileEntry } from '@ionic-native/file'; +import { FileEntry } from '@ionic-native/file/ngx'; import { CoreFileSession } from '@services/file-session'; import { CoreFormFields } from '@singletons/form'; -import { CoreWSExternalFile } from '@services/ws'; import { makeSingleton, Translate } from '@singletons'; import { AddonModDataFieldFileComponent } from '../component/file'; +import { CoreFileEntry } from '@services/file-helper'; /** * Handler for file data field plugin. @@ -77,7 +77,7 @@ export class AddonModDataFieldFileHandlerService implements AddonModDataFieldHan /** * @inheritdoc */ - getFieldEditFiles(field: AddonModDataField): (CoreWSExternalFile | FileEntry)[] { + getFieldEditFiles(field: AddonModDataField): CoreFileEntry[] { return CoreFileSession.getFiles(AddonModDataProvider.COMPONENT, field.dataid + '_' + field.id); } diff --git a/src/addons/mod/data/fields/picture/component/picture.ts b/src/addons/mod/data/fields/picture/component/picture.ts index 11d19be88..7c64674e1 100644 --- a/src/addons/mod/data/fields/picture/component/picture.ts +++ b/src/addons/mod/data/fields/picture/component/picture.ts @@ -13,10 +13,9 @@ // limitations under the License. import { AddonModDataEntryField, AddonModDataProvider } from '@addons/mod/data/services/data'; import { Component } from '@angular/core'; -import { FileEntry } from '@ionic-native/file'; +import { CoreFileEntry, CoreFileHelper } from '@services/file-helper'; import { CoreFileSession } from '@services/file-session'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreWSExternalFile } from '@services/ws'; import { AddonModDataFieldPluginComponent } from '../../../classes/field-plugin-component'; /** @@ -28,12 +27,12 @@ import { AddonModDataFieldPluginComponent } from '../../../classes/field-plugin- }) export class AddonModDataFieldPictureComponent extends AddonModDataFieldPluginComponent { - files: (CoreWSExternalFile | FileEntry)[] = []; + files: CoreFileEntry[] = []; component?: string; componentId?: number; maxSizeBytes?: number; - image?: CoreWSExternalFile | FileEntry; + image?: CoreFileEntry; entryId?: number; imageUrl?: string; title?: string; @@ -46,7 +45,7 @@ export class AddonModDataFieldPictureComponent extends AddonModDataFieldPluginCo * @param value Input value. * @return List of files. */ - protected getFiles(value?: Partial): (CoreWSExternalFile | FileEntry)[] { + protected getFiles(value?: Partial): CoreFileEntry[] { let files = value?.files || []; // Reduce to first element. @@ -65,9 +64,9 @@ export class AddonModDataFieldPictureComponent extends AddonModDataFieldPluginCo * @return File found or false. */ protected findFile( - files: (CoreWSExternalFile | FileEntry)[], + files: CoreFileEntry[], filenameSeek: string, - ): CoreWSExternalFile | FileEntry | undefined { + ): CoreFileEntry | undefined { return files.find((file) => ('name' in file ? file.name : file.filename) == filenameSeek) || undefined; } @@ -130,7 +129,7 @@ export class AddonModDataFieldPictureComponent extends AddonModDataFieldPluginCo if (this.image) { this.imageUrl = 'name' in this.image ? this.image.toURL() // Is Offline. - : this.image.fileurl; + : CoreFileHelper.getFileUrl(this.image); } }, 1); diff --git a/src/addons/mod/data/fields/picture/services/handler.ts b/src/addons/mod/data/fields/picture/services/handler.ts index cd1c26dac..24937cdd9 100644 --- a/src/addons/mod/data/fields/picture/services/handler.ts +++ b/src/addons/mod/data/fields/picture/services/handler.ts @@ -22,12 +22,12 @@ import { import { AddonModDataFieldHandler } from '@addons/mod/data/services/data-fields-delegate'; import { Injectable, Type } from '@angular/core'; import { CoreFileUploader, CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader'; -import { FileEntry } from '@ionic-native/file'; +import { FileEntry } from '@ionic-native/file/ngx'; import { CoreFileSession } from '@services/file-session'; import { CoreFormFields } from '@singletons/form'; -import { CoreWSExternalFile } from '@services/ws'; import { makeSingleton, Translate } from '@singletons'; import { AddonModDataFieldPictureComponent } from '../component/picture'; +import { CoreFileEntry } from '@services/file-helper'; /** * Handler for picture data field plugin. @@ -88,7 +88,7 @@ export class AddonModDataFieldPictureHandlerService implements AddonModDataField /** * @inheritdoc */ - getFieldEditFiles(field: AddonModDataField): (CoreWSExternalFile | FileEntry)[] { + getFieldEditFiles(field: AddonModDataField): CoreFileEntry[] { return CoreFileSession.getFiles(AddonModDataProvider.COMPONENT, field.dataid + '_' + field.id); } diff --git a/src/addons/mod/data/fields/textarea/component/textarea.ts b/src/addons/mod/data/fields/textarea/component/textarea.ts index 8b459b8ef..e8cc52d5d 100644 --- a/src/addons/mod/data/fields/textarea/component/textarea.ts +++ b/src/addons/mod/data/fields/textarea/component/textarea.ts @@ -16,7 +16,7 @@ import { Component } from '@angular/core'; import { AddonModDataFieldPluginComponent } from '../../../classes/field-plugin-component'; import { AddonModDataEntryField, AddonModDataProvider } from '@addons/mod/data/services/data'; import { CoreTextUtils } from '@services/utils/text'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; /** * Component to render data number field. @@ -37,7 +37,7 @@ export class AddonModDataFieldTextareaComponent extends AddonModDataFieldPluginC * @return Replaced string to be rendered. */ format(value?: Partial): string { - const files: CoreWSExternalFile[] = (value && value.files) || []; + const files: CoreWSFile[] = (value && value.files) || []; return value ? CoreTextUtils.replacePluginfileUrls(value.content || '', files) : ''; } diff --git a/src/addons/mod/data/fields/textarea/services/handler.ts b/src/addons/mod/data/fields/textarea/services/handler.ts index 2bfc9b85f..9eac09d39 100644 --- a/src/addons/mod/data/fields/textarea/services/handler.ts +++ b/src/addons/mod/data/fields/textarea/services/handler.ts @@ -14,13 +14,13 @@ import { AddonModDataEntryField, AddonModDataField, AddonModDataSubfieldData } from '@addons/mod/data/services/data'; import { Injectable, Type } from '@angular/core'; -import { FileEntry } from '@ionic-native/file'; import { CoreFormFields } from '@singletons/form'; import { CoreTextUtils } from '@services/utils/text'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { makeSingleton, Translate } from '@singletons'; import { AddonModDataFieldTextHandlerService } from '../../text/services/handler'; import { AddonModDataFieldTextareaComponent } from '../component/textarea'; +import { CoreFileEntry } from '@services/file-helper'; /** * Handler for textarea data field plugin. @@ -49,7 +49,7 @@ export class AddonModDataFieldTextareaHandlerService extends AddonModDataFieldTe const fieldName = 'f_' + field.id; const files = this.getFieldEditFiles(field, inputData, originalFieldData); - let text = CoreTextUtils.restorePluginfileUrls(inputData[fieldName] || '', files); + let text = CoreTextUtils.restorePluginfileUrls(inputData[fieldName] || '', files); // Add some HTML to the text if needed. text = CoreTextUtils.formatHtmlLines(text); @@ -83,7 +83,7 @@ export class AddonModDataFieldTextareaHandlerService extends AddonModDataFieldTe field: AddonModDataField, inputData: CoreFormFields, originalFieldData: AddonModDataEntryField, - ): (CoreWSExternalFile | FileEntry)[] { + ): CoreFileEntry[] { return (originalFieldData && originalFieldData.files) || []; } @@ -116,7 +116,7 @@ export class AddonModDataFieldTextareaHandlerService extends AddonModDataFieldTe // Take the original files since we cannot edit them on the app. originalContent.content = CoreTextUtils.replacePluginfileUrls( originalContent.content, - originalContent.files, + originalContent.files, ); } diff --git a/src/addons/mod/data/services/data-fields-delegate.ts b/src/addons/mod/data/services/data-fields-delegate.ts index 0c79e29a0..e6509241b 100644 --- a/src/addons/mod/data/services/data-fields-delegate.ts +++ b/src/addons/mod/data/services/data-fields-delegate.ts @@ -22,8 +22,8 @@ import { AddonModDataEntryField, AddonModDataSubfieldData, } from './data'; import { CoreFormFields } from '@singletons/form'; -import { CoreWSExternalFile } from '@services/ws'; -import { FileEntry } from '@ionic-native/file'; +import { FileEntry } from '@ionic-native/file/ngx'; +import { CoreFileEntry } from '@services/file-helper'; /** * Interface that all fields handlers must implement. @@ -94,7 +94,7 @@ export interface AddonModDataFieldHandler extends CoreDelegateHandler { field: AddonModDataField, inputData: CoreFormFields, originalFieldData: AddonModDataEntryField, - ): (CoreWSExternalFile | FileEntry)[]; + ): CoreFileEntry[]; /** * Check and get field requeriments. @@ -183,7 +183,7 @@ export class AddonModDataFieldsDelegateService extends CoreDelegate { + ): Promise { if (!inputData) { return []; } @@ -745,7 +745,7 @@ export class AddonModDataHelperProvider { dataId: number, entryId: number, fieldId: number, - files: (CoreWSExternalFile | FileEntry)[], + files: CoreFileEntry[], siteId?: string, ): Promise { // Get the folder where to store the files. @@ -771,7 +771,7 @@ export class AddonModDataHelperProvider { itemId: number = 0, entryId: number, fieldId: number, - files: (CoreWSExternalFile | FileEntry)[], + files: CoreFileEntry[], offline: boolean, siteId?: string, ): Promise { diff --git a/src/addons/mod/data/services/data-sync.ts b/src/addons/mod/data/services/data-sync.ts index b89e4b2a6..c54158cfd 100644 --- a/src/addons/mod/data/services/data-sync.ts +++ b/src/addons/mod/data/services/data-sync.ts @@ -21,13 +21,12 @@ import { CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader'; import { CoreRatingSync } from '@features/rating/services/rating-sync'; -import { FileEntry } from '@ionic-native/file'; import { CoreApp } from '@services/app'; +import { CoreFileEntry } from '@services/file-helper'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSync } from '@services/sync'; import { CoreTextUtils } from '@services/utils/text'; import { CoreUtils } from '@services/utils/utils'; -import { CoreWSExternalFile } from '@services/ws'; import { Translate, makeSingleton } from '@singletons'; import { CoreEvents } from '@singletons/events'; import { AddonModDataProvider, AddonModData, AddonModDataData, AddonModDataAction } from './data'; @@ -348,7 +347,7 @@ export class AddonModDataSyncProvider extends CoreCourseActivitySyncBaseProvider // Upload Files if asked. const value = CoreTextUtils.parseJSON(field.value || ''); if (value.online || value.offline) { - let files: (CoreWSExternalFile | FileEntry)[] = value.online || []; + let files: CoreFileEntry[] = value.online || []; const offlineFiles = value.offline ? await AddonModDataHelper.getStoredFiles(editAction.dataid, entryId, field.fieldid) diff --git a/src/addons/mod/data/services/data.ts b/src/addons/mod/data/services/data.ts index 4b3af40c1..44203896a 100644 --- a/src/addons/mod/data/services/data.ts +++ b/src/addons/mod/data/services/data.ts @@ -19,8 +19,8 @@ import { CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreRatingInfo } from '@features/rating/services/rating'; import { CoreTagItem } from '@features/tag/services/tag'; -import { FileEntry } from '@ionic-native/file'; import { CoreApp } from '@services/app'; +import { CoreFileEntry } from '@services/file-helper'; import { CoreFilepool } from '@services/filepool'; import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; @@ -1151,7 +1151,7 @@ export type AddonModDataEntryField = { content2: string; // Contents. content3: string; // Contents. content4: string; // Contents. - files: (CoreWSExternalFile | FileEntry)[]; + files: CoreFileEntry[]; }; /** @@ -1180,7 +1180,7 @@ export type AddonModDataSubfieldData = { fieldid: number; subfield?: string; value?: unknown; // Value encoded in JSON. - files?: (CoreWSExternalFile | FileEntry)[]; + files?: CoreFileEntry[]; }; /** diff --git a/src/addons/mod/data/services/handlers/default-field.ts b/src/addons/mod/data/services/handlers/default-field.ts index 3eec28e1a..a25fc5d7b 100644 --- a/src/addons/mod/data/services/handlers/default-field.ts +++ b/src/addons/mod/data/services/handlers/default-field.ts @@ -11,9 +11,9 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. + import { Injectable } from '@angular/core'; -import { FileEntry } from '@ionic-native/file'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreFileEntry } from '@services/file-helper'; import { AddonModDataEntryField, AddonModDataSearchEntriesAdvancedFieldFormatted, AddonModDataSubfieldData } from '../data'; import { AddonModDataFieldHandler } from '../data-fields-delegate'; @@ -50,7 +50,7 @@ export class AddonModDataDefaultFieldHandler implements AddonModDataFieldHandler /** * @inheritdoc */ - getFieldEditFiles(): (CoreWSExternalFile | FileEntry)[] { + getFieldEditFiles(): CoreFileEntry[] { return []; } diff --git a/src/addons/mod/data/services/handlers/prefetch.ts b/src/addons/mod/data/services/handlers/prefetch.ts index 7a8106596..e67b65a49 100644 --- a/src/addons/mod/data/services/handlers/prefetch.ts +++ b/src/addons/mod/data/services/handlers/prefetch.ts @@ -21,7 +21,7 @@ import { CoreGroup, CoreGroups } from '@services/groups'; import { CoreSitesCommonWSOptions, CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreTimeUtils } from '@services/utils/time'; import { CoreUtils } from '@services/utils/utils'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonModDataProvider, AddonModDataEntry, AddonModData, AddonModDataData } from '../data'; import { AddonModDataSync, AddonModDataSyncResult } from '../data-sync'; @@ -82,10 +82,10 @@ export class AddonModDataPrefetchHandlerService extends CoreCourseActivityPrefet courseId: number, omitFail: boolean, options: CoreCourseCommonModWSOptions = {}, - ): Promise<{ database: AddonModDataData; groups: CoreGroup[]; entries: AddonModDataEntry[]; files: CoreWSExternalFile[]}> { + ): Promise<{ database: AddonModDataData; groups: CoreGroup[]; entries: AddonModDataEntry[]; files: CoreWSFile[]}> { let groups: CoreGroup[] = []; let entries: AddonModDataEntry[] = []; - let files: CoreWSExternalFile[] = []; + let files: CoreWSFile[] = []; options.cmId = options.cmId || module.id; options.siteId = options.siteId || CoreSites.getCurrentSiteId(); @@ -131,12 +131,12 @@ export class AddonModDataPrefetchHandlerService extends CoreCourseActivityPrefet * @param entries List of entries to get files from. * @return List of files. */ - protected getEntriesFiles(entries: AddonModDataEntry[]): CoreWSExternalFile[] { - let files: CoreWSExternalFile[] = []; + protected getEntriesFiles(entries: AddonModDataEntry[]): CoreWSFile[] { + let files: CoreWSFile[] = []; entries.forEach((entry) => { CoreUtils.objectToArray(entry.contents).forEach((content) => { - files = files.concat(content.files); + files = files.concat(content.files); }); }); @@ -146,14 +146,14 @@ export class AddonModDataPrefetchHandlerService extends CoreCourseActivityPrefet /** * @inheritdoc */ - async getFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { + async getFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { return this.getDatabaseInfoHelper(module, courseId, true).then((info) => info.files); } /** * @inheritdoc */ - async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { + async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { const data = await CoreUtils.ignoreErrors(AddonModData.getDatabase(courseId, module.id)); return this.getIntroFilesFromInstance(module, data); diff --git a/src/addons/mod/forum/components/edit-post/edit-post.ts b/src/addons/mod/forum/components/edit-post/edit-post.ts index 1070e5c4b..e3a81636c 100644 --- a/src/addons/mod/forum/components/edit-post/edit-post.ts +++ b/src/addons/mod/forum/components/edit-post/edit-post.ts @@ -14,13 +14,14 @@ import { Component, ViewChild, ElementRef, Input, OnInit } from '@angular/core'; import { FormControl } from '@angular/forms'; -import { CoreFileEntry, CoreFileUploader } from '@features/fileuploader/services/fileuploader'; +import { CoreFileUploader } from '@features/fileuploader/services/fileuploader'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { ModalController, Translate } from '@singletons'; import { AddonModForumData, AddonModForumPost, AddonModForumReply } from '@addons/mod/forum/services/forum'; import { AddonModForumHelper } from '@addons/mod/forum/services/forum-helper'; import { CoreForms } from '@singletons/form'; +import { CoreFileEntry } from '@services/file-helper'; /** * Page that displays a form to edit discussion post. diff --git a/src/addons/mod/forum/components/post/post.ts b/src/addons/mod/forum/components/post/post.ts index e86cfd393..cd394baf3 100644 --- a/src/addons/mod/forum/components/post/post.ts +++ b/src/addons/mod/forum/components/post/post.ts @@ -38,11 +38,10 @@ import { AddonModForumProvider, AddonModForumReply, AddonModForumUpdateDiscussionPostWSOptionsObject, - AddonModForumWSPostAttachment, } from '../../services/forum'; import { CoreTag } from '@features/tag/services/tag'; import { ModalController, PopoverController, Translate } from '@singletons'; -import { CoreFileEntry, CoreFileUploader } from '@features/fileuploader/services/fileuploader'; +import { CoreFileUploader } from '@features/fileuploader/services/fileuploader'; import { IonContent } from '@ionic/angular'; import { AddonModForumSync } from '../../services/forum-sync'; import { CoreSync } from '@services/sync'; @@ -54,6 +53,7 @@ import { AddonModForumPostOptionsMenuComponent } from '../post-options-menu/post import { AddonModForumEditPostComponent } from '../edit-post/edit-post'; import { CoreRatingInfo } from '@features/rating/services/rating'; import { CoreForms } from '@singletons/form'; +import { CoreFileEntry } from '@services/file-helper'; /** * Components that shows a discussion post, its attachments and the action buttons allowed (reply, etc.). @@ -186,7 +186,7 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges isEditing?: boolean, subject?: string, message?: string, - files?: (CoreFileEntry | AddonModForumWSPostAttachment)[], + files?: CoreFileEntry[], isPrivate?: boolean, ): void { // Delete the local files from the tmp folder if any. diff --git a/src/addons/mod/forum/services/forum-helper.ts b/src/addons/mod/forum/services/forum-helper.ts index c479f1045..b3a570eef 100644 --- a/src/addons/mod/forum/services/forum-helper.ts +++ b/src/addons/mod/forum/services/forum-helper.ts @@ -14,7 +14,7 @@ import { Injectable } from '@angular/core'; import { FileEntry } from '@ionic-native/file/ngx'; -import { CoreFileEntry, CoreFileUploader, CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader'; +import { CoreFileUploader, CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader'; import { CoreUser } from '@features/user/services/user'; import { CoreApp } from '@services/app'; import { CoreFile } from '@services/file'; @@ -31,6 +31,7 @@ import { AddonModForumProvider, } from './forum'; import { AddonModForumDiscussionOptions, AddonModForumOffline, AddonModForumOfflineReply } from './forum-offline'; +import { CoreFileEntry } from '@services/file-helper'; /** * Service that provides some features for forums. diff --git a/src/addons/mod/forum/services/forum.ts b/src/addons/mod/forum/services/forum.ts index e860ef5de..ea4a088a3 100644 --- a/src/addons/mod/forum/services/forum.ts +++ b/src/addons/mod/forum/services/forum.ts @@ -16,17 +16,17 @@ import { Injectable } from '@angular/core'; import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; import { CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { CoreCourseLogHelper } from '@features/course/services/log-helper'; -import { CoreFileEntry } from '@features/fileuploader/services/fileuploader'; import { CoreRatingInfo } from '@features/rating/services/rating'; import { CoreTagItem } from '@features/tag/services/tag'; import { CoreUser } from '@features/user/services/user'; import { CoreApp } from '@services/app'; +import { CoreFileEntry } from '@services/file-helper'; import { CoreFilepool } from '@services/filepool'; import { CoreGroups } from '@services/groups'; import { CoreSitesCommonWSOptions, CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreUrlUtils } from '@services/utils/url'; import { CoreUtils } from '@services/utils/utils'; -import { CoreStatusWithWarningsWSResponse, CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws'; +import { CoreStatusWithWarningsWSResponse, CoreWSExternalFile, CoreWSExternalWarning, CoreWSStoredFile } from '@services/ws'; import { makeSingleton, Translate } from '@singletons'; import { AddonModForumOffline, AddonModForumOfflineDiscussion, AddonModForumReplyOptions } from './forum-offline'; @@ -1469,7 +1469,7 @@ export type AddonModForumPost = { canreplyprivately?: boolean; // Whether the user can post a private reply. }; attachment?: 0 | 1; - attachments?: (CoreFileEntry | AddonModForumWSPostAttachment)[]; + attachments?: CoreFileEntry[]; messageinlinefiles?: CoreWSExternalFile[]; haswordcount?: boolean; // Haswordcount. wordcount?: number; // Wordcount. @@ -1580,7 +1580,7 @@ export type AddonModForumReply = { id: number; subject: string; message: string; - files: (CoreFileEntry | AddonModForumWSPostAttachment)[]; + files: CoreFileEntry[]; }; /** @@ -1600,37 +1600,6 @@ export type AddonModForumSortOrder = { value: number; }; -/** - * Forum post attachement data returned by web services. - */ -export type AddonModForumWSPostAttachment = { - contextid: number; // Contextid. - component: string; // Component. - filearea: string; // Filearea. - itemid: number; // Itemid. - filepath: string; // Filepath. - filename: string; // Filename. - isdir: boolean; // Isdir. - isimage: boolean; // Isimage. - timemodified: number; // Timemodified. - timecreated: number; // Timecreated. - filesize: number; // Filesize. - author: string; // Author. - license: string; // License. - filenameshort: string; // Filenameshort. - filesizeformatted: string; // Filesizeformatted. - icon: string; // Icon. - timecreatedformatted: string; // Timecreatedformatted. - timemodifiedformatted: string; // Timemodifiedformatted. - url: string; // Url. - urls: { - export?: string; // The URL used to export the attachment. - }; - html: { - plagiarism?: string; // The HTML source for the Plagiarism Response. - }; -}; - /** * Forum post data returned by web services. */ @@ -1693,7 +1662,7 @@ export type AddonModForumWSPost = { markasunread?: string; // The URL used to mark the post as unread. discuss?: string; // Discuss. }; - attachments: AddonModForumWSPostAttachment[]; // Attachments. + attachments: CoreWSStoredFile[]; // Attachments. tags?: { // Tags. id: number; // The ID of the Tag. tagid: number; // The tagid. diff --git a/src/addons/mod/forum/services/handlers/prefetch.ts b/src/addons/mod/forum/services/handlers/prefetch.ts index c303ec8a0..a9c55d2e9 100644 --- a/src/addons/mod/forum/services/handlers/prefetch.ts +++ b/src/addons/mod/forum/services/handlers/prefetch.ts @@ -17,7 +17,7 @@ import { CoreCourseActivityPrefetchHandlerBase } from '@features/course/classes/ import { AddonModForum, AddonModForumData, AddonModForumPost, AddonModForumProvider } from '../forum'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreFilepool } from '@services/filepool'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { CoreCourse, CoreCourseAnyModuleData, CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { CoreUser } from '@features/user/services/user'; import { CoreGroups, CoreGroupsProvider } from '@services/groups'; @@ -44,7 +44,7 @@ export class AddonModForumPrefetchHandlerService extends CoreCourseActivityPrefe * @param single True if we're downloading a single module, false if we're downloading a whole section. * @return Promise resolved with the list of files. */ - async getFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { + async getFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { try { const forum = await AddonModForum.getForum(courseId, module.id); @@ -69,13 +69,13 @@ export class AddonModForumPrefetchHandlerService extends CoreCourseActivityPrefe * @param posts Forum posts. * @return Files. */ - protected getPostsFiles(posts: AddonModForumPost[]): CoreWSExternalFile[] { - let files: CoreWSExternalFile[] = []; + protected getPostsFiles(posts: AddonModForumPost[]): CoreWSFile[] { + let files: CoreWSFile[] = []; const getInlineFiles = CoreSites.getCurrentSite()?.isVersionGreaterEqualThan('3.2'); posts.forEach((post) => { if (post.attachments && post.attachments.length) { - files = files.concat(post.attachments as CoreWSExternalFile[]); + files = files.concat(post.attachments as CoreWSFile[]); } if (getInlineFiles && post.messageinlinefiles && post.messageinlinefiles.length) { files = files.concat(post.messageinlinefiles); diff --git a/src/addons/mod/glossary/services/glossary-helper.ts b/src/addons/mod/glossary/services/glossary-helper.ts index a970e3d77..1e25ddffd 100644 --- a/src/addons/mod/glossary/services/glossary-helper.ts +++ b/src/addons/mod/glossary/services/glossary-helper.ts @@ -20,7 +20,7 @@ import { CoreUtils } from '@services/utils/utils'; import { AddonModGlossaryOffline } from './glossary-offline'; import { AddonModGlossaryNewEntry, AddonModGlossaryNewEntryWithFiles } from './glossary'; import { makeSingleton } from '@singletons'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreFileEntry } from '@services/file-helper'; /** * Helper to gather some common functions for glossary. @@ -68,7 +68,7 @@ export class AddonModGlossaryHelperProvider { */ hasEntryDataChanged( entry: AddonModGlossaryNewEntry, - files: (CoreWSExternalFile | FileEntry)[], + files: CoreFileEntry[], original?: AddonModGlossaryNewEntryWithFiles, ): boolean { if (!original || typeof original.concept == 'undefined') { @@ -98,7 +98,7 @@ export class AddonModGlossaryHelperProvider { glossaryId: number, entryName: string, timeCreated: number, - files: (CoreWSExternalFile | FileEntry)[], + files: CoreFileEntry[], siteId?: string, ): Promise { // Get the folder where to store the files. diff --git a/src/addons/mod/glossary/services/glossary-sync.ts b/src/addons/mod/glossary/services/glossary-sync.ts index 3502a82a5..80a2fbe0d 100644 --- a/src/addons/mod/glossary/services/glossary-sync.ts +++ b/src/addons/mod/glossary/services/glossary-sync.ts @@ -14,7 +14,6 @@ import { ContextLevel } from '@/core/constants'; import { Injectable } from '@angular/core'; -import { FileEntry } from '@ionic-native/file/ngx'; import { CoreSyncBlockedError } from '@classes/base-sync'; import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/activity-sync'; @@ -24,13 +23,13 @@ import { CoreApp } from '@services/app'; import { CoreSites } from '@services/sites'; import { CoreSync } from '@services/sync'; import { CoreUtils } from '@services/utils/utils'; -import { CoreWSExternalFile } from '@services/ws'; import { makeSingleton, Translate } from '@singletons'; import { CoreEvents } from '@singletons/events'; import { AddonModGlossary, AddonModGlossaryProvider } from './glossary'; import { AddonModGlossaryHelper } from './glossary-helper'; import { AddonModGlossaryOffline, AddonModGlossaryOfflineEntry } from './glossary-offline'; import { CoreFileUploader } from '@features/fileuploader/services/fileuploader'; +import { CoreFileEntry } from '@services/file-helper'; /** * Service to sync glossaries. @@ -309,7 +308,7 @@ export class AddonModGlossarySyncProvider extends CoreCourseActivitySyncBaseProv } // Has some attachments to sync. - let files: (CoreWSExternalFile | FileEntry)[] = entry.attachments.online || []; + let files: CoreFileEntry[] = entry.attachments.online || []; if (entry.attachments.offline) { // Has offline files. diff --git a/src/addons/mod/glossary/services/glossary.ts b/src/addons/mod/glossary/services/glossary.ts index b34767f4a..4efd33ccd 100644 --- a/src/addons/mod/glossary/services/glossary.ts +++ b/src/addons/mod/glossary/services/glossary.ts @@ -13,7 +13,6 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { FileEntry } from '@ionic-native/file/ngx'; import { CoreError } from '@classes/errors/error'; import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; import { CoreCourseCommonModWSOptions } from '@features/course/services/course'; @@ -30,6 +29,7 @@ import { makeSingleton, Translate } from '@singletons'; import { AddonModGlossaryEntryDBRecord, ENTRIES_TABLE_NAME } from './database/glossary'; import { AddonModGlossaryOffline } from './glossary-offline'; import { AddonModGlossaryAutoSyncData, AddonModGlossarySyncProvider } from './glossary-sync'; +import { CoreFileEntry } from '@services/file-helper'; const ROOT_CACHE_KEY = 'mmaModGlossary:'; @@ -1431,7 +1431,7 @@ export type AddonModGlossaryNewEntry = { * Entry to be added, including attachments. */ export type AddonModGlossaryNewEntryWithFiles = AddonModGlossaryNewEntry & { - files: (CoreWSExternalFile | FileEntry)[]; + files: CoreFileEntry[]; }; /** diff --git a/src/addons/mod/glossary/services/handlers/prefetch.ts b/src/addons/mod/glossary/services/handlers/prefetch.ts index cc92048a0..a153527a1 100644 --- a/src/addons/mod/glossary/services/handlers/prefetch.ts +++ b/src/addons/mod/glossary/services/handlers/prefetch.ts @@ -19,7 +19,7 @@ import { CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/c import { CoreUser } from '@features/user/services/user'; import { CoreFilepool } from '@services/filepool'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonModGlossary, AddonModGlossaryEntry, AddonModGlossaryGlossary, AddonModGlossaryProvider } from '../glossary'; import { AddonModGlossarySync, AddonModGlossarySyncResult } from '../glossary-sync'; @@ -38,7 +38,7 @@ export class AddonModGlossaryPrefetchHandlerService extends CoreCourseActivityPr /** * @inheritdoc */ - async getFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { + async getFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { try { const glossary = await AddonModGlossary.getGlossary(courseId, module.id); @@ -68,7 +68,7 @@ export class AddonModGlossaryPrefetchHandlerService extends CoreCourseActivityPr module: CoreCourseAnyModuleData, glossary: AddonModGlossaryGlossary, entries: AddonModGlossaryEntry[], - ): CoreWSExternalFile[] { + ): CoreWSFile[] { let files = this.getIntroFilesFromInstance(module, glossary); const getInlineFiles = CoreSites.getCurrentSite()?.isVersionGreaterEqualThan('3.2'); diff --git a/src/addons/mod/h5pactivity/components/index/index.ts b/src/addons/mod/h5pactivity/components/index/index.ts index 43c57aaa8..f8dfdccba 100644 --- a/src/addons/mod/h5pactivity/components/index/index.ts +++ b/src/addons/mod/h5pactivity/components/index/index.ts @@ -30,7 +30,7 @@ import { CoreFilepool } from '@services/filepool'; import { CoreNavigator } from '@services/navigator'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { AddonModH5PActivity, @@ -43,6 +43,7 @@ import { AddonModH5PActivitySyncProvider, AddonModH5PActivitySyncResult, } from '../../services/h5pactivity-sync'; +import { CoreFileHelper } from '@services/file-helper'; /** * Component that displays an H5P activity entry page. @@ -58,7 +59,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv h5pActivity?: AddonModH5PActivityData; // The H5P activity object. accessInfo?: AddonModH5PActivityAccessInfo; // Info about the user capabilities. - deployedFile?: CoreWSExternalFile; // The H5P deployed file. + deployedFile?: CoreWSFile; // The H5P deployed file. stateMessage?: string; // Message about the file state. downloading = false; // Whether the H5P file is being downloaded. @@ -191,10 +192,10 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv siteId: this.siteId, }); - this.fileUrl = this.deployedFile.fileurl; + this.fileUrl = CoreFileHelper.getFileUrl(this.deployedFile); // Listen for changes in the state. - const eventName = await CoreFilepool.getFileEventNameByUrl(this.site.getId(), this.deployedFile.fileurl); + const eventName = await CoreFilepool.getFileEventNameByUrl(this.site.getId(), this.fileUrl); if (!this.observer) { this.observer = CoreEvents.on(eventName, () => { @@ -213,7 +214,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv protected async calculateFileState(): Promise { this.state = await CoreFilepool.getFileStateByUrl( this.site.getId(), - this.deployedFile!.fileurl, + this.fileUrl!, this.deployedFile!.timemodified, ); @@ -317,7 +318,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv try { await CoreFilepool.downloadUrl( this.site.getId(), - this.deployedFile!.fileurl, + this.fileUrl!, false, this.component, this.componentId, diff --git a/src/addons/mod/h5pactivity/services/h5pactivity.ts b/src/addons/mod/h5pactivity/services/h5pactivity.ts index 3b9d8c7d3..fe19c45ac 100644 --- a/src/addons/mod/h5pactivity/services/h5pactivity.ts +++ b/src/addons/mod/h5pactivity/services/h5pactivity.ts @@ -15,7 +15,7 @@ import { Injectable } from '@angular/core'; import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites'; -import { CoreWSExternalWarning, CoreWSExternalFile } from '@services/ws'; +import { CoreWSExternalWarning, CoreWSExternalFile, CoreWSFile } from '@services/ws'; import { CoreTimeUtils } from '@services/utils/time'; import { CoreUtils } from '@services/utils/utils'; import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; @@ -305,7 +305,7 @@ export class AddonModH5PActivityProvider { async getDeployedFile( h5pActivity: AddonModH5PActivityData, options?: AddonModH5PActivityGetDeployedFileOptions, - ): Promise { + ): Promise { if (h5pActivity.deployedfile) { // File already deployed and still valid, use this one. diff --git a/src/addons/mod/h5pactivity/services/handlers/prefetch.ts b/src/addons/mod/h5pactivity/services/handlers/prefetch.ts index 03a41dead..6c6d6cf8e 100644 --- a/src/addons/mod/h5pactivity/services/handlers/prefetch.ts +++ b/src/addons/mod/h5pactivity/services/handlers/prefetch.ts @@ -21,7 +21,7 @@ import { CoreH5P } from '@features/h5p/services/h5p'; import { CoreUser } from '@features/user/services/user'; import { CoreFilepool } from '@services/filepool'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonModH5PActivity, AddonModH5PActivityData, AddonModH5PActivityProvider } from '../h5pactivity'; @@ -39,7 +39,7 @@ export class AddonModH5PActivityPrefetchHandlerService extends CoreCourseActivit /** * @inheritdoc */ - async getFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { + async getFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { const h5pActivity = await AddonModH5PActivity.getH5PActivity(courseId, module.id); diff --git a/src/addons/mod/imscp/services/handlers/prefetch.ts b/src/addons/mod/imscp/services/handlers/prefetch.ts index 66b3f835f..fb95f9898 100644 --- a/src/addons/mod/imscp/services/handlers/prefetch.ts +++ b/src/addons/mod/imscp/services/handlers/prefetch.ts @@ -23,7 +23,7 @@ import { import { CoreFilepool } from '@services/filepool'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonModImscp, AddonModImscpProvider } from '../imscp'; @@ -58,7 +58,7 @@ export class AddonModImscpPrefetchHandlerService extends CoreCourseResourcePrefe /** * @inheritdoc */ - async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { + async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { // If not found, use undefined so module description is used. const imscp = await CoreUtils.ignoreErrors(AddonModImscp.getImscp(courseId, module.id)); diff --git a/src/addons/mod/label/services/handlers/prefetch.ts b/src/addons/mod/label/services/handlers/prefetch.ts index 91c583f43..ba7a0b950 100644 --- a/src/addons/mod/label/services/handlers/prefetch.ts +++ b/src/addons/mod/label/services/handlers/prefetch.ts @@ -17,7 +17,7 @@ import { CoreCourseResourcePrefetchHandlerBase } from '@features/course/classes/ import { CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/course'; import { CoreSitesReadingStrategy } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonModLabel, AddonModLabelLabel, AddonModLabelProvider } from '../label'; @@ -36,7 +36,7 @@ export class AddonModLabelPrefetchHandlerService extends CoreCourseResourcePrefe /** * @inheritdoc */ - async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number, ignoreCache?: boolean): Promise { + async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number, ignoreCache?: boolean): Promise { let label: AddonModLabelLabel | undefined; if (AddonModLabel.isGetLabelAvailableForSite()) { diff --git a/src/addons/mod/lesson/services/handlers/prefetch.ts b/src/addons/mod/lesson/services/handlers/prefetch.ts index 7180e172c..def77488d 100644 --- a/src/addons/mod/lesson/services/handlers/prefetch.ts +++ b/src/addons/mod/lesson/services/handlers/prefetch.ts @@ -23,7 +23,7 @@ import { CoreGroups } from '@services/groups'; import { CoreFileSizeSum, CorePluginFileDelegate } from '@services/plugin-file-delegate'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { makeSingleton, ModalController, Translate } from '@singletons'; import { AddonModLessonPasswordModalComponent } from '../../components/password-modal/password-modal'; import { @@ -92,7 +92,7 @@ export class AddonModLessonPrefetchHandlerService extends CoreCourseActivityPref lesson = passwordData.lesson || lesson; // Get intro files and media files. - let files = lesson.mediafiles || []; + let files: CoreWSFile[] = lesson.mediafiles || []; files = files.concat(this.getIntroFilesFromInstance(module, lesson)); const result = await CorePluginFileDelegate.getFilesDownloadSize(files); @@ -289,7 +289,8 @@ export class AddonModLessonPrefetchHandlerService extends CoreCourseActivityPref const promises: Promise[] = []; // Download intro files and media files. - const files = (lesson.mediafiles || []).concat(this.getIntroFilesFromInstance(module, lesson)); + let files: CoreWSFile[] = (lesson.mediafiles || []); + files = files.concat(this.getIntroFilesFromInstance(module, lesson)); promises.push(CoreFilepool.addFilesToQueue(siteId, files, this.component, module.id)); if (AddonModLesson.isLessonOffline(lesson)) { @@ -495,7 +496,7 @@ export class AddonModLessonPrefetchHandlerService extends CoreCourseActivityPref } // Download embedded files in essays. - const files: CoreWSExternalFile[] = []; + const files: CoreWSFile[] = []; attempt.answerpages.forEach((answerPage) => { if (!answerPage.page || answerPage.page.qtype != AddonModLessonProvider.LESSON_PAGE_ESSAY) { return; diff --git a/src/addons/mod/quiz/services/handlers/prefetch.ts b/src/addons/mod/quiz/services/handlers/prefetch.ts index 76a718017..0528dee8f 100644 --- a/src/addons/mod/quiz/services/handlers/prefetch.ts +++ b/src/addons/mod/quiz/services/handlers/prefetch.ts @@ -23,7 +23,7 @@ import { CoreFilepool } from '@services/filepool'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreTextUtils } from '@services/utils/text'; import { CoreUtils } from '@services/utils/utils'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonModQuizAccessRuleDelegate } from '../access-rules-delegate'; import { @@ -77,7 +77,7 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet * @return Promise resolved with the list of files. */ // eslint-disable-next-line @typescript-eslint/no-unused-vars - async getFiles(module: CoreCourseAnyModuleData, courseId: number, single?: boolean): Promise { + async getFiles(module: CoreCourseAnyModuleData, courseId: number, single?: boolean): Promise { try { const quiz = await AddonModQuiz.getQuiz(courseId, module.id); @@ -109,9 +109,9 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet quiz: AddonModQuizQuizWSData, attempts: AddonModQuizAttemptWSData[], siteId?: string, - ): Promise { + ): Promise { const getInlineFiles = CoreSites.getCurrentSite()?.isVersionGreaterEqualThan('3.2'); - let files: CoreWSExternalFile[] = []; + let files: CoreWSFile[] = []; await Promise.all(attempts.map(async (attempt) => { if (!AddonModQuiz.isAttemptFinished(attempt.state)) { diff --git a/src/addons/mod/resource/services/handlers/module.ts b/src/addons/mod/resource/services/handlers/module.ts index 7e05beb73..ea4e3ee50 100644 --- a/src/addons/mod/resource/services/handlers/module.ts +++ b/src/addons/mod/resource/services/handlers/module.ts @@ -22,7 +22,7 @@ import { CoreNavigationOptions, CoreNavigator } from '@services/navigator'; import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreTextUtils } from '@services/utils/text'; import { CoreTimeUtils } from '@services/utils/time'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { makeSingleton, Translate } from '@singletons'; import { AddonModResourceIndexComponent } from '../../components/index'; import { AddonModResource, AddonModResourceCustomData } from '../resource'; @@ -142,7 +142,7 @@ export class AddonModResourceModuleHandlerService implements CoreCourseModuleHan handlerData: CoreCourseModuleHandlerData, ): Promise { const promises: Promise[] = []; - let infoFiles: CoreWSExternalFile[] = []; + let infoFiles: CoreWSFile[] = []; let options: AddonModResourceCustomData = {}; // Check if the button needs to be shown or not. @@ -166,7 +166,7 @@ export class AddonModResourceModuleHandlerService implements CoreCourseModuleHan await Promise.all(promises); - const files: (CoreCourseModuleContentFile | CoreWSExternalFile)[] = module.contents && module.contents.length + const files: (CoreCourseModuleContentFile | CoreWSFile)[] = module.contents && module.contents.length ? module.contents : infoFiles; diff --git a/src/addons/mod/scorm/services/handlers/prefetch.ts b/src/addons/mod/scorm/services/handlers/prefetch.ts index 6c174cf11..634082609 100644 --- a/src/addons/mod/scorm/services/handlers/prefetch.ts +++ b/src/addons/mod/scorm/services/handlers/prefetch.ts @@ -22,7 +22,7 @@ import { CoreFilepool } from '@services/filepool'; import { CoreFileSizeSum } from '@services/plugin-file-delegate'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { makeSingleton, Translate } from '@singletons'; import { AddonModScorm, AddonModScormProvider, AddonModScormScorm } from '../scorm'; import { AddonModScormSync } from '../scorm-sync'; @@ -297,7 +297,7 @@ export class AddonModScormPrefetchHandlerService extends CoreCourseActivityPrefe * @param single True if we're downloading a single module, false if we're downloading a whole section. * @return Promise resolved with the list of files. */ - async getFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { + async getFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { try { const scorm = await this.getScorm(module, courseId); diff --git a/src/addons/mod/scorm/services/scorm.ts b/src/addons/mod/scorm/services/scorm.ts index 5920b727f..4383c6d87 100644 --- a/src/addons/mod/scorm/services/scorm.ts +++ b/src/addons/mod/scorm/services/scorm.ts @@ -25,7 +25,7 @@ import { CoreTextUtils } from '@services/utils/text'; import { CoreTimeUtils } from '@services/utils/time'; import { CoreUrlUtils } from '@services/utils/url'; import { CoreUtils } from '@services/utils/utils'; -import { CoreWS, CoreWSExternalFile, CoreWSExternalWarning, CoreWSPreSets } from '@services/ws'; +import { CoreWS, CoreWSExternalFile, CoreWSExternalWarning, CoreWSFile, CoreWSPreSets } from '@services/ws'; import { makeSingleton, Translate } from '@singletons'; import { CoreEvents } from '@singletons/events'; import { AddonModScormOffline } from './scorm-offline'; @@ -983,8 +983,8 @@ export class AddonModScormProvider { * @param scorm SCORM. * @return File list. */ - getScormFileList(scorm: AddonModScormScorm): CoreWSExternalFile[] { - const files: CoreWSExternalFile[] = []; + getScormFileList(scorm: AddonModScormScorm): CoreWSFile[] { + const files: CoreWSFile[] = []; if (!this.isScormUnsupported(scorm) && !scorm.warningMessage) { files.push({ diff --git a/src/addons/mod/survey/services/handlers/prefetch.ts b/src/addons/mod/survey/services/handlers/prefetch.ts index c856f5656..0ccae56eb 100644 --- a/src/addons/mod/survey/services/handlers/prefetch.ts +++ b/src/addons/mod/survey/services/handlers/prefetch.ts @@ -18,7 +18,7 @@ import { CoreCourseAnyModuleData } from '@features/course/services/course'; import { CoreFilepool } from '@services/filepool'; import { CoreSitesReadingStrategy } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonModSurvey, AddonModSurveyProvider } from '../survey'; import { AddonModSurveySync, AddonModSurveySyncResult } from '../survey-sync'; @@ -37,7 +37,7 @@ export class AddonModSurveyPrefetchHandlerService extends CoreCourseActivityPref /** * @inheritdoc */ - async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { + async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { const survey = await CoreUtils.ignoreErrors(AddonModSurvey.getSurvey(courseId, module.id)); return this.getIntroFilesFromInstance(module, survey); diff --git a/src/addons/mod/wiki/pages/edit/edit.ts b/src/addons/mod/wiki/pages/edit/edit.ts index 312c77050..ab1497894 100644 --- a/src/addons/mod/wiki/pages/edit/edit.ts +++ b/src/addons/mod/wiki/pages/edit/edit.ts @@ -23,7 +23,7 @@ import { CoreSync } from '@services/sync'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreTextUtils } from '@services/utils/text'; import { CoreUtils } from '@services/utils/utils'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { Translate } from '@singletons'; import { CoreEvents } from '@singletons/events'; import { CoreForms } from '@singletons/form'; @@ -62,7 +62,7 @@ export class AddonModWikiEditPage implements OnInit, OnDestroy, CanLeave { protected blockId?: string; // ID to block the subwiki. protected editing = false; // Whether the user is editing a page (true) or creating a new one (false). protected editOffline = false; // Whether the user is editing an offline page. - protected subwikiFiles: CoreWSExternalFile[] = []; // List of files of the subwiki. + protected subwikiFiles: CoreWSFile[] = []; // List of files of the subwiki. protected originalContent?: string; // The original page content. protected version?: number; // Page version. protected renewLockInterval?: number; // An interval to renew the lock every certain time. diff --git a/src/addons/mod/wiki/services/handlers/prefetch.ts b/src/addons/mod/wiki/services/handlers/prefetch.ts index fee992462..22b6e4922 100644 --- a/src/addons/mod/wiki/services/handlers/prefetch.ts +++ b/src/addons/mod/wiki/services/handlers/prefetch.ts @@ -21,7 +21,7 @@ import { CoreGroups } from '@services/groups'; import { CoreFileSizeSum, CorePluginFileDelegate } from '@services/plugin-file-delegate'; import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonModWiki, AddonModWikiProvider, AddonModWikiSubwikiPage } from '../wiki'; import { AddonModWikiSync, AddonModWikiSyncWikiResult } from '../wiki-sync'; @@ -103,7 +103,7 @@ export class AddonModWikiPrefetchHandlerService extends CoreCourseActivityPrefet courseId: number, single?: boolean, siteId?: string, - ): Promise { + ): Promise { siteId = siteId || CoreSites.getCurrentSiteId(); try { diff --git a/src/addons/mod/wiki/services/wiki.ts b/src/addons/mod/wiki/services/wiki.ts index da636b222..6dc180136 100644 --- a/src/addons/mod/wiki/services/wiki.ts +++ b/src/addons/mod/wiki/services/wiki.ts @@ -22,7 +22,7 @@ import { CoreApp } from '@services/app'; import { CoreNavigator } from '@services/navigator'; import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; -import { CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws'; +import { CoreWSExternalFile, CoreWSExternalWarning, CoreWSFile } from '@services/ws'; import { makeSingleton, Translate } from '@singletons'; import { CoreEvents } from '@singletons/events'; import { AddonModWikiPageDBRecord } from './database/wiki'; @@ -196,7 +196,7 @@ export class AddonModWikiProvider { * @param options Other options. * @return Promise resolved with subwiki files. */ - async getSubwikiFiles(wikiId: number, options: AddonModWikiGetSubwikiFilesOptions = {}): Promise { + async getSubwikiFiles(wikiId: number, options: AddonModWikiGetSubwikiFilesOptions = {}): Promise { const site = await CoreSites.getSite(options.siteId); const groupId = options.groupId || -1; @@ -426,10 +426,10 @@ export class AddonModWikiProvider { * @param options Other options. * @return Promise resolved with the list of files. */ - async getWikiFileList(wiki: AddonModWikiWiki, options: CoreSitesCommonWSOptions = {}): Promise { + async getWikiFileList(wiki: AddonModWikiWiki, options: CoreSitesCommonWSOptions = {}): Promise { options.siteId = options.siteId || CoreSites.getCurrentSiteId(); - let files: CoreWSExternalFile[] = []; + let files: CoreWSFile[] = []; const modOptions = { cmId: wiki.coursemodule, ...options, // Include all options. diff --git a/src/addons/qtype/ddmarker/services/handlers/ddmarker.ts b/src/addons/qtype/ddmarker/services/handlers/ddmarker.ts index 1bcdbed82..eb74174dc 100644 --- a/src/addons/qtype/ddmarker/services/handlers/ddmarker.ts +++ b/src/addons/qtype/ddmarker/services/handlers/ddmarker.ts @@ -17,7 +17,7 @@ import { Injectable, Type } from '@angular/core'; import { CoreQuestion, CoreQuestionQuestionParsed, CoreQuestionsAnswers } from '@features/question/services/question'; import { CoreQuestionHandler } from '@features/question/services/question-delegate'; import { CoreQuestionHelper, CoreQuestionQuestion } from '@features/question/services/question-helper'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonQtypeDdMarkerComponent } from '../../component/ddmarker'; @@ -135,7 +135,7 @@ export class AddonQtypeDdMarkerHandlerService implements CoreQuestionHandler { * @param usageId Usage ID. * @return List of files or URLs. */ - getAdditionalDownloadableFiles(question: CoreQuestionQuestionParsed, usageId?: number): CoreWSExternalFile[] { + getAdditionalDownloadableFiles(question: CoreQuestionQuestionParsed, usageId?: number): CoreWSFile[] { const treatedQuestion: CoreQuestionQuestion = question; CoreQuestionHelper.extractQuestionScripts(treatedQuestion, usageId); diff --git a/src/addons/qtype/essay/component/essay.ts b/src/addons/qtype/essay/component/essay.ts index 44da3e59b..16e1c75d2 100644 --- a/src/addons/qtype/essay/component/essay.ts +++ b/src/addons/qtype/essay/component/essay.ts @@ -20,9 +20,9 @@ import { CoreFileUploaderStoreFilesResult } from '@features/fileuploader/service import { AddonModQuizEssayQuestion, CoreQuestionBaseComponent } from '@features/question/classes/base-question-component'; import { CoreQuestionHelper } from '@features/question/services/question-helper'; import { CoreTextUtils } from '@services/utils/text'; -import { CoreWSExternalFile } from '@services/ws'; import { CoreFileSession } from '@services/file-session'; import { CoreQuestion } from '@features/question/services/question'; +import { CoreFileEntry } from '@services/file-helper'; /** * Component to render an essay question. */ @@ -33,7 +33,7 @@ import { CoreQuestion } from '@features/question/services/question'; export class AddonQtypeEssayComponent extends CoreQuestionBaseComponent implements OnInit { formControl?: FormControl; - attachments?: (CoreWSExternalFile | FileEntry)[]; + attachments?: CoreFileEntry[]; uploadFilesSupported = false; essayQuestion?: AddonModQuizEssayQuestion; diff --git a/src/addons/qtype/essay/services/handlers/essay.ts b/src/addons/qtype/essay/services/handlers/essay.ts index 053e7d1eb..e651af56b 100644 --- a/src/addons/qtype/essay/services/handlers/essay.ts +++ b/src/addons/qtype/essay/services/handlers/essay.ts @@ -25,7 +25,7 @@ import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreTextUtils } from '@services/utils/text'; import { CoreUtils } from '@services/utils/utils'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonQtypeEssayComponent } from '../../component/essay'; @@ -81,12 +81,12 @@ export class AddonQtypeEssayHandlerService implements CoreQuestionHandler { * @param usageId Usage ID. * @return List of files or URLs. */ - getAdditionalDownloadableFiles(question: CoreQuestionQuestionParsed): CoreWSExternalFile[] { + getAdditionalDownloadableFiles(question: CoreQuestionQuestionParsed): CoreWSFile[] { if (!question.responsefileareas) { return []; } - return question.responsefileareas.reduce((urlsList, area) => urlsList.concat(area.files || []), []); + return question.responsefileareas.reduce((urlsList, area) => urlsList.concat(area.files || []), []); } /** diff --git a/src/core/components/attachments/attachments.ts b/src/core/components/attachments/attachments.ts index 341da812e..b541e1947 100644 --- a/src/core/components/attachments/attachments.ts +++ b/src/core/components/attachments/attachments.ts @@ -18,11 +18,11 @@ import { FileEntry } from '@ionic-native/file/ngx'; import { CoreFileUploader, CoreFileUploaderTypeList } from '@features/fileuploader/services/fileuploader'; import { CoreSites } from '@services/sites'; import { CoreTextUtils } from '@services/utils/text'; -import { CoreWSExternalFile } from '@services/ws'; import { Translate } from '@singletons'; import { CoreApp } from '@services/app'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreFileUploaderHelper } from '@features/fileuploader/services/fileuploader-helper'; +import { CoreFileEntry } from '@services/file-helper'; /** * Component to render attachments, allow adding more and delete the current ones. @@ -43,7 +43,7 @@ import { CoreFileUploaderHelper } from '@features/fileuploader/services/fileuplo }) export class CoreAttachmentsComponent implements OnInit { - @Input() files?: (CoreWSExternalFile | FileEntry)[]; // List of attachments. New attachments will be added to this array. + @Input() files?: CoreFileEntry[]; // List of attachments. New attachments will be added to this array. @Input() maxSize?: number; // Max size for attachments. -1 means unlimited, 0 means user max size, not defined means unknown. @Input() maxSubmissions?: number; // Max number of attachments. -1 means unlimited, not defined means unknown limit. @Input() component?: string; // Component the downloaded files will be linked to. diff --git a/src/core/components/file/file.ts b/src/core/components/file/file.ts index b821892c1..f595bf994 100644 --- a/src/core/components/file/file.ts +++ b/src/core/components/file/file.ts @@ -25,7 +25,7 @@ import { CoreUtils } from '@services/utils/utils'; import { CoreTextUtils } from '@services/utils/text'; import { CoreConstants } from '@/core/constants'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; /** * Component to handle a remote file. Shows the file name, icon (depending on mimetype) and a button @@ -38,7 +38,7 @@ import { CoreWSExternalFile } from '@services/ws'; }) export class CoreFileComponent implements OnInit, OnDestroy { - @Input() file?: CoreWSExternalFile; // The file. + @Input() file?: CoreWSFile; // The file. @Input() component?: string; // Component the file belongs to. @Input() componentId?: string | number; // Component ID. @Input() canDelete?: boolean | string; // Whether file can be deleted. @@ -76,7 +76,7 @@ export class CoreFileComponent implements OnInit, OnDestroy { this.alwaysDownload = CoreUtils.isTrueOrOne(this.alwaysDownload); this.canDownload = CoreUtils.isTrueOrOne(this.canDownload); - this.fileUrl = this.file.fileurl; + this.fileUrl = CoreFileHelper.getFileUrl(this.file); this.timemodified = this.file.timemodified || 0; this.siteId = CoreSites.getCurrentSiteId(); this.fileSize = this.file.filesize; @@ -88,12 +88,12 @@ export class CoreFileComponent implements OnInit, OnDestroy { this.showTime = CoreUtils.isTrueOrOne(this.showTime) && this.timemodified > 0; - if (this.file.isexternalfile) { + if ('isexternalfile' in this.file && this.file.isexternalfile) { this.alwaysDownload = true; // Always show the download button in external files. } - this.fileIcon = this.file.mimetype ? CoreMimetypeUtils.getMimetypeIcon(this.file.mimetype) : - CoreMimetypeUtils.getFileIcon(this.fileName); + this.fileIcon = 'mimetype' in this.file && this.file.mimetype ? + CoreMimetypeUtils.getMimetypeIcon(this.file.mimetype) : CoreMimetypeUtils.getFileIcon(this.fileName); if (this.canDownload) { this.calculateState(); diff --git a/src/core/components/files/files.ts b/src/core/components/files/files.ts index 694b764f6..b17358e65 100644 --- a/src/core/components/files/files.ts +++ b/src/core/components/files/files.ts @@ -13,11 +13,10 @@ // limitations under the License. import { Component, Input, OnInit, DoCheck, KeyValueDiffers } from '@angular/core'; -import { FileEntry } from '@ionic-native/file/ngx'; +import { CoreFileEntry } from '@services/file-helper'; import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreUtils } from '@services/utils/utils'; -import { CoreWSExternalFile } from '@services/ws'; /** * Component to render a file list. @@ -31,7 +30,7 @@ import { CoreWSExternalFile } from '@services/ws'; }) export class CoreFilesComponent implements OnInit, DoCheck { - @Input() files?: (CoreWSExternalFile | FileEntry)[]; // List of files. + @Input() files?: CoreFileEntry[]; // List of files. @Input() component?: string; // Component the downloaded files will be linked to. @Input() componentId?: string | number; // Component ID. @Input() alwaysDownload?: boolean | string; // Whether it should always display the refresh button when the file is downloaded. diff --git a/src/core/features/course/classes/module-prefetch-handler.ts b/src/core/features/course/classes/module-prefetch-handler.ts index 1df8285e0..e68b13c68 100644 --- a/src/core/features/course/classes/module-prefetch-handler.ts +++ b/src/core/features/course/classes/module-prefetch-handler.ts @@ -15,7 +15,7 @@ import { CoreFilepool } from '@services/filepool'; import { CoreFileSizeSum, CorePluginFileDelegate } from '@services/plugin-file-delegate'; import { CoreSites } from '@services/sites'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { CoreCourse, CoreCourseAnyModuleData, CoreCourseModuleContentFile } from '../services/course'; import { CoreCourseModulePrefetchHandler } from '../services/module-prefetch-delegate'; @@ -154,7 +154,7 @@ export class CoreCourseModulePrefetchHandlerBase implements CoreCourseModulePref * @return Promise resolved with the list of files. */ // eslint-disable-next-line @typescript-eslint/no-unused-vars - async getFiles(module: CoreCourseAnyModuleData, courseId: number, single?: boolean): Promise { + async getFiles(module: CoreCourseAnyModuleData, courseId: number, single?: boolean): Promise { // To be overridden. return []; } @@ -168,7 +168,7 @@ export class CoreCourseModulePrefetchHandlerBase implements CoreCourseModulePref * @return Promise resolved with list of intro files. */ // eslint-disable-next-line @typescript-eslint/no-unused-vars - async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number, ignoreCache?: boolean): Promise { + async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number, ignoreCache?: boolean): Promise { return this.getIntroFilesFromInstance(module); } @@ -179,7 +179,7 @@ export class CoreCourseModulePrefetchHandlerBase implements CoreCourseModulePref * @param instance The instance to get the intro files (book, assign, ...). If not defined, module will be used. * @return List of intro files. */ - getIntroFilesFromInstance(module: CoreCourseAnyModuleData, instance?: ModuleInstance): CoreWSExternalFile[] { + getIntroFilesFromInstance(module: CoreCourseAnyModuleData, instance?: ModuleInstance): CoreWSFile[] { if (instance) { if (typeof instance.introfiles != 'undefined') { return instance.introfiles; @@ -339,6 +339,6 @@ export class CoreCourseModulePrefetchHandlerBase implements CoreCourseModulePref * Properties a module instance should have to be able to retrieve its intro files. */ type ModuleInstance = { - introfiles?: CoreWSExternalFile[]; + introfiles?: CoreWSFile[]; intro?: string; }; diff --git a/src/core/features/course/classes/resource-prefetch-handler.ts b/src/core/features/course/classes/resource-prefetch-handler.ts index b12025a2d..67880f2ae 100644 --- a/src/core/features/course/classes/resource-prefetch-handler.ts +++ b/src/core/features/course/classes/resource-prefetch-handler.ts @@ -18,7 +18,7 @@ import { CoreFilterHelper } from '@features/filter/services/filter-helper'; import { CoreApp } from '@services/app'; import { CoreFilepool } from '@services/filepool'; import { CoreSites } from '@services/sites'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { CoreCourse, CoreCourseAnyModuleData, CoreCourseWSModule } from '../services/course'; import { CoreCourseModulePrefetchHandlerBase } from './module-prefetch-handler'; @@ -144,7 +144,7 @@ export class CoreCourseResourcePrefetchHandlerBase extends CoreCourseModulePrefe * @return Promise resolved with the list of files. */ // eslint-disable-next-line @typescript-eslint/no-unused-vars - async getFiles(module: CoreCourseWSModule, courseId: number, single?: boolean): Promise { + async getFiles(module: CoreCourseWSModule, courseId: number, single?: boolean): Promise { // Load module contents if needed. await this.loadContents(module, courseId); diff --git a/src/core/features/course/services/module-prefetch-delegate.ts b/src/core/features/course/services/module-prefetch-delegate.ts index f06387f67..aca8154ae 100644 --- a/src/core/features/course/services/module-prefetch-delegate.ts +++ b/src/core/features/course/services/module-prefetch-delegate.ts @@ -30,7 +30,7 @@ import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate'; import { makeSingleton } from '@singletons'; import { CoreEvents, CoreEventSectionStatusChangedData } from '@singletons/events'; import { CoreError } from '@classes/errors/error'; -import { CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws'; +import { CoreWSFile, CoreWSExternalWarning } from '@services/ws'; import { CHECK_UPDATES_TIMES_TABLE, CoreCourseCheckUpdatesDBRecord } from './database/module-prefetch'; import { CoreFileSizeSum } from '@services/plugin-file-delegate'; @@ -458,7 +458,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { - const path = await CoreFilepool.getFilePathByUrl(siteId, file.fileurl || ''); + const path = await CoreFilepool.getFilePathByUrl(siteId, CoreFileHelper.getFileUrl(file)); try { const fileSize = await CoreFile.getFileSize(path); @@ -467,7 +467,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { + ): Promise<(CoreWSFile | CoreCourseModuleContentFile)[]> { const handler = this.getPrefetchHandlerFor(module); if (handler?.getFiles) { @@ -1192,7 +1192,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { - await CoreUtils.ignoreErrors(CoreFilepool.removeFileByUrl(siteId, file.fileurl || '')); + await CoreUtils.ignoreErrors(CoreFilepool.removeFileByUrl(siteId, CoreFileHelper.getFileUrl(file))); })); } @@ -1462,7 +1462,7 @@ export interface CoreCourseModulePrefetchHandler extends CoreDelegateHandler { * @param courseId Course ID the module belongs to. * @return List of files, or promise resolved with the files. */ - getFiles?(module: CoreCourseAnyModuleData, courseId: number): Promise<(CoreWSExternalFile | CoreCourseModuleContentFile)[]>; + getFiles?(module: CoreCourseAnyModuleData, courseId: number): Promise<(CoreWSFile | CoreCourseModuleContentFile)[]>; /** * Check if a certain module has updates based on the result of check updates. diff --git a/src/core/features/fileuploader/services/fileuploader-delegate.ts b/src/core/features/fileuploader/services/fileuploader-delegate.ts index 6bcb5146e..6614590a9 100644 --- a/src/core/features/fileuploader/services/fileuploader-delegate.ts +++ b/src/core/features/fileuploader/services/fileuploader-delegate.ts @@ -13,7 +13,7 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { FileEntry } from '@ionic-native/file'; +import { FileEntry } from '@ionic-native/file/ngx'; import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate'; import { CoreEvents } from '@singletons/events'; diff --git a/src/core/features/fileuploader/services/fileuploader.ts b/src/core/features/fileuploader/services/fileuploader.ts index 342815f33..c9546f807 100644 --- a/src/core/features/fileuploader/services/fileuploader.ts +++ b/src/core/features/fileuploader/services/fileuploader.ts @@ -26,12 +26,13 @@ import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreTextUtils } from '@services/utils/text'; import { CoreTimeUtils } from '@services/utils/time'; import { CoreUtils } from '@services/utils/utils'; -import { CoreWSExternalFile, CoreWSFileUploadOptions, CoreWSUploadFileResult } from '@services/ws'; +import { CoreWSFile, CoreWSFileUploadOptions, CoreWSUploadFileResult } from '@services/ws'; import { makeSingleton, Translate, MediaCapture, ModalController, Camera } from '@singletons'; import { CoreLogger } from '@singletons/logger'; import { CoreEmulatorCaptureMediaComponent } from '@features/emulator/components/capture-media/capture-media'; import { CoreError } from '@classes/errors/error'; import { CoreSite } from '@classes/site'; +import { CoreFileEntry, CoreFileHelper } from '@services/file-helper'; /** * File upload options. @@ -80,7 +81,7 @@ export class CoreFileUploaderProvider { * @param b Second file list. * @return Whether both lists are different. */ - areFileListDifferent(a: (CoreWSExternalFile | FileEntry)[], b: (CoreWSExternalFile | FileEntry)[]): boolean { + areFileListDifferent(a: CoreFileEntry[], b: CoreFileEntry[]): boolean { a = a || []; b = b || []; if (a.length != b.length) { @@ -194,7 +195,7 @@ export class CoreFileUploaderProvider { * * @param files List of files. */ - clearTmpFiles(files: (CoreWSExternalFile | FileEntry)[]): void { + clearTmpFiles(files: (CoreWSFile | FileEntry)[]): void { // Delete the local files. files.forEach((file) => { if ('remove' in file) { @@ -275,15 +276,16 @@ export class CoreFileUploaderProvider { * @return List of files to delete. */ getFilesToDelete( - originalFiles: CoreWSExternalFile[], - currentFiles: (CoreWSExternalFile | FileEntry)[], + originalFiles: CoreWSFile[], + currentFiles: CoreFileEntry[], ): { filepath: string; filename: string }[] { const filesToDelete: { filepath: string; filename: string }[] = []; currentFiles = currentFiles || []; originalFiles.forEach((file) => { - const stillInList = currentFiles.some((currentFile) => ( currentFile).fileurl == file.fileurl); + const stillInList = currentFiles.some((currentFile) => + CoreFileHelper.getFileUrl( currentFile) == CoreFileHelper.getFileUrl(file)); if (!stillInList) { filesToDelete.push({ @@ -391,8 +393,8 @@ export class CoreFileUploaderProvider { async getStoredFilesFromOfflineFilesObject( filesObject: CoreFileUploaderStoreFilesResult, folderPath: string, - ): Promise<(CoreWSExternalFile | FileEntry)[]> { - let files: (CoreWSExternalFile | FileEntry)[] = []; + ): Promise { + let files: CoreFileEntry[] = []; if (filesObject.online.length > 0) { files = CoreUtils.clone(filesObject.online); @@ -550,7 +552,7 @@ export class CoreFileUploaderProvider { */ async storeFilesToUpload( folderPath: string, - files: (CoreWSExternalFile | FileEntry)[], + files: CoreFileEntry[], ): Promise { const result: CoreFileUploaderStoreFilesResult = { online: [], @@ -569,7 +571,7 @@ export class CoreFileUploaderProvider { // It's an online file, add it to the result and ignore it. result.online.push({ filename: file.filename, - fileurl: file.fileurl, + fileurl: CoreFileHelper.getFileUrl(file), }); } else if (file.fullPath?.indexOf(folderPath) != -1) { // File already in the submission folder. @@ -629,7 +631,7 @@ export class CoreFileUploaderProvider { * @param siteId Site ID. If not defined, current site. * @return Promise resolved with the itemId. */ - async uploadFiles(itemId: number, files: (CoreWSExternalFile | FileEntry)[], siteId?: string): Promise { + async uploadFiles(itemId: number, files: CoreFileEntry[], siteId?: string): Promise { siteId = siteId || CoreSites.getCurrentSiteId(); if (!files || !files.length) { @@ -637,7 +639,7 @@ export class CoreFileUploaderProvider { } // Index the online files by name. - const usedNames: {[name: string]: (CoreWSExternalFile | FileEntry)} = {}; + const usedNames: {[name: string]: CoreFileEntry} = {}; const filesToUpload: FileEntry[] = []; files.forEach((file) => { if (CoreUtils.isFileEntry(file)) { @@ -674,7 +676,7 @@ export class CoreFileUploaderProvider { * @return Promise resolved with the itemId. */ async uploadOrReuploadFile( - file: CoreWSExternalFile | FileEntry, + file: CoreFileEntry, itemId?: number, component?: string, componentId?: string | number, @@ -697,7 +699,7 @@ export class CoreFileUploaderProvider { const path = await CoreFilepool.downloadUrl( siteId, - file.fileurl, + CoreFileHelper.getFileUrl(file), false, component, componentId, @@ -734,7 +736,7 @@ export class CoreFileUploaderProvider { * @return Promise resolved with the itemId. */ async uploadOrReuploadFiles( - files: (CoreWSExternalFile | FileEntry)[], + files: CoreFileEntry[], component?: string, componentId?: string | number, siteId?: string, @@ -766,7 +768,7 @@ export class CoreFileUploaderProvider { export const CoreFileUploader = makeSingleton(CoreFileUploaderProvider); export type CoreFileUploaderStoreFilesResult = { - online: CoreWSExternalFile[]; // List of online files. + online: CoreWSFile[]; // List of online files. offline: number; // Number of offline files. }; @@ -779,5 +781,3 @@ export type CoreFileUploaderTypeListInfoEntry = { name?: string; extlist: string; }; - -export type CoreFileEntry = CoreWSExternalFile | FileEntry; diff --git a/src/core/features/h5p/classes/helper.ts b/src/core/features/h5p/classes/helper.ts index 4054bcb01..9724e29a3 100644 --- a/src/core/features/h5p/classes/helper.ts +++ b/src/core/features/h5p/classes/helper.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { FileEntry } from '@ionic-native/file'; +import { FileEntry } from '@ionic-native/file/ngx'; import { CoreFile, CoreFileProvider } from '@services/file'; import { CoreSites } from '@services/sites'; diff --git a/src/core/features/h5p/services/h5p.ts b/src/core/features/h5p/services/h5p.ts index 9a6bc3b0d..7bf8cf078 100644 --- a/src/core/features/h5p/services/h5p.ts +++ b/src/core/features/h5p/services/h5p.ts @@ -15,7 +15,7 @@ import { Injectable } from '@angular/core'; import { CoreSites } from '@services/sites'; -import { CoreWSExternalWarning, CoreWSExternalFile } from '@services/ws'; +import { CoreWSExternalWarning, CoreWSExternalFile, CoreWSFile } from '@services/ws'; import { CoreTextUtils } from '@services/utils/text'; import { CoreUrlUtils } from '@services/utils/url'; import { CoreQueueRunner } from '@classes/queue-runner'; @@ -95,7 +95,7 @@ export class CoreH5PProvider { options?: CoreH5PGetTrustedFileOptions, ignoreCache?: boolean, siteId?: string, - ): Promise { + ): Promise { options = options || {}; diff --git a/src/core/features/h5p/services/handlers/pluginfile.ts b/src/core/features/h5p/services/handlers/pluginfile.ts index 879710aec..48723ae70 100644 --- a/src/core/features/h5p/services/handlers/pluginfile.ts +++ b/src/core/features/h5p/services/handlers/pluginfile.ts @@ -13,7 +13,7 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { FileEntry } from '@ionic-native/file'; +import { FileEntry } from '@ionic-native/file/ngx'; import { CoreFilepoolOnProgressCallback } from '@services/filepool'; import { CorePluginFileDownloadableResult, CorePluginFileHandler } from '@services/plugin-file-delegate'; @@ -21,10 +21,11 @@ import { CoreSites } from '@services/sites'; import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreUrlUtils } from '@services/utils/url'; import { CoreUtils } from '@services/utils/utils'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { CoreH5P } from '../h5p'; import { Translate, makeSingleton } from '@singletons'; import { CoreH5PHelper } from '../../classes/helper'; +import { CoreFileHelper } from '@services/file-helper'; /** * Handler to treat H5P files. @@ -54,15 +55,17 @@ export class CoreH5PPluginFileHandlerService implements CorePluginFileHandler { * @param siteId Site ID. If not defined, current site. * @return Promise resolved with the file to use. Rejected if cannot download. */ - async getDownloadableFile(file: CoreWSExternalFile, siteId?: string): Promise { + async getDownloadableFile(file: CoreWSFile, siteId?: string): Promise { const site = await CoreSites.getSite(siteId); - if (site.containsUrl(file.fileurl) && file.fileurl.match(/pluginfile\.php\/[^/]+\/core_h5p\/export\//i)) { + const fileUrl = CoreFileHelper.getFileUrl(file); + + if (site.containsUrl(fileUrl) && fileUrl.match(/pluginfile\.php\/[^/]+\/core_h5p\/export\//i)) { // It's already a deployed file, use it. return file; } - return CoreH5P.getTrustedH5PFile(file.fileurl, {}, false, siteId); + return CoreH5P.getTrustedH5PFile(fileUrl, {}, false, siteId); } /** @@ -94,7 +97,7 @@ export class CoreH5PPluginFileHandlerService implements CorePluginFileHandler { * @param siteId Site ID. If not defined, current site. * @return Promise resolved with the size. */ - async getFileSize(file: CoreWSExternalFile, siteId?: string): Promise { + async getFileSize(file: CoreWSFile, siteId?: string): Promise { try { const trustedFile = await this.getDownloadableFile(file, siteId); @@ -125,7 +128,7 @@ export class CoreH5PPluginFileHandlerService implements CorePluginFileHandler { * @param siteId Site ID. If not defined, current site. * @return Promise resolved with a boolean and a reason why it isn't downloadable if needed. */ - async isFileDownloadable(file: CoreWSExternalFile, siteId?: string): Promise { + async isFileDownloadable(file: CoreWSFile, siteId?: string): Promise { const offlineDisabled = await CoreH5P.isOfflineDisabled(siteId); if (offlineDisabled) { @@ -146,8 +149,8 @@ export class CoreH5PPluginFileHandlerService implements CorePluginFileHandler { * @param file The file data. * @return Whether the file should be treated by this handler. */ - shouldHandleFile(file: CoreWSExternalFile): boolean { - return CoreMimetypeUtils.guessExtensionFromUrl(file.fileurl) == 'h5p'; + shouldHandleFile(file: CoreWSFile): boolean { + return CoreMimetypeUtils.guessExtensionFromUrl(CoreFileHelper.getFileUrl(file)) == 'h5p'; } /** diff --git a/src/core/features/question/classes/base-question-component.ts b/src/core/features/question/classes/base-question-component.ts index f22757bb5..7be8ed33f 100644 --- a/src/core/features/question/classes/base-question-component.ts +++ b/src/core/features/question/classes/base-question-component.ts @@ -18,7 +18,7 @@ import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreTextUtils } from '@services/utils/text'; import { CoreUrlUtils } from '@services/utils/url'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { CoreLogger } from '@singletons/logger'; import { CoreQuestionBehaviourButton, CoreQuestionHelper, CoreQuestionQuestion } from '../services/question-helper'; @@ -715,7 +715,7 @@ export type AddonModQuizEssayQuestion = AddonModQuizQuestionBasicData & { isPlainText?: boolean; // Whether the answer is plain text. hasInlineText?: boolean; // // Whether the answer has inline text answer?: string; // Question answer text. - attachments?: CoreWSExternalFile[]; // Question answer attachments. + attachments?: CoreWSFile[]; // Question answer attachments. hasDraftFiles?: boolean; // Whether the question has draft files. textarea?: AddonModQuizQuestionTextarea; // Textarea data. formatInput?: { name: string; value: string }; // Format input data. diff --git a/src/core/features/question/services/question-delegate.ts b/src/core/features/question/services/question-delegate.ts index 4810ca620..ff3d1bc01 100644 --- a/src/core/features/question/services/question-delegate.ts +++ b/src/core/features/question/services/question-delegate.ts @@ -15,7 +15,7 @@ import { Injectable, Type } from '@angular/core'; import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { CoreQuestionDefaultHandler } from './handlers/default-question'; import { CoreQuestionQuestionParsed, CoreQuestionsAnswers } from './question'; @@ -143,7 +143,7 @@ export interface CoreQuestionHandler extends CoreDelegateHandler { * @param usageId Usage ID. * @return List of files or URLs. */ - getAdditionalDownloadableFiles?(question: CoreQuestionQuestionParsed, usageId?: number): CoreWSExternalFile[]; + getAdditionalDownloadableFiles?(question: CoreQuestionQuestionParsed, usageId?: number): CoreWSFile[]; /** * Clear temporary data after the data has been saved. @@ -393,7 +393,7 @@ export class CoreQuestionDelegateService extends CoreDelegate { let content = anchor.innerHTML; @@ -464,7 +465,7 @@ export class CoreQuestionHelperProvider { * @param areaName Name of the area, e.g. 'attachments'. * @return List of files. */ - getResponseFileAreaFiles(question: CoreQuestionQuestion, areaName: string): CoreWSExternalFile[] { + getResponseFileAreaFiles(question: CoreQuestionQuestion, areaName: string): CoreWSFile[] { if (!question.responsefileareas) { return []; } @@ -642,22 +643,23 @@ export class CoreQuestionHelperProvider { await Promise.all(files.map(async (file) => { const timemodified = file.timemodified || 0; + const fileUrl = CoreFileHelper.getFileUrl(file); - if (treated[file.fileurl]) { + if (treated[fileUrl]) { return; } - treated[file.fileurl] = true; + treated[fileUrl] = true; - if (!site.canDownloadFiles() && CoreUrlUtils.isPluginFileUrl(file.fileurl)) { + if (!site.canDownloadFiles() && CoreUrlUtils.isPluginFileUrl(fileUrl)) { return; } - if (file.fileurl.indexOf('theme/image.php') > -1 && file.fileurl.indexOf('flagged') > -1) { + if (fileUrl.indexOf('theme/image.php') > -1 && fileUrl.indexOf('flagged') > -1) { // Ignore flag images. return; } - await CoreFilepool.addToQueueByUrl(site.getId(), file.fileurl, component, componentId, timemodified); + await CoreFilepool.addToQueueByUrl(site.getId(), fileUrl, component, componentId, timemodified); })); } diff --git a/src/core/features/sharedfiles/components/list-modal/list-modal.ts b/src/core/features/sharedfiles/components/list-modal/list-modal.ts index c06f27796..f3ba2f873 100644 --- a/src/core/features/sharedfiles/components/list-modal/list-modal.ts +++ b/src/core/features/sharedfiles/components/list-modal/list-modal.ts @@ -13,7 +13,7 @@ // limitations under the License. import { Component, OnInit, Input } from '@angular/core'; -import { FileEntry } from '@ionic-native/file'; +import { FileEntry } from '@ionic-native/file/ngx'; import { CoreFile } from '@services/file'; import { ModalController, Translate } from '@singletons'; diff --git a/src/core/features/sharedfiles/components/list/list.ts b/src/core/features/sharedfiles/components/list/list.ts index d915ba50f..936c2b71c 100644 --- a/src/core/features/sharedfiles/components/list/list.ts +++ b/src/core/features/sharedfiles/components/list/list.ts @@ -13,7 +13,7 @@ // limitations under the License. import { Component, OnInit, OnDestroy, Input, Output, EventEmitter } from '@angular/core'; -import { FileEntry, DirectoryEntry } from '@ionic-native/file'; +import { FileEntry, DirectoryEntry } from '@ionic-native/file/ngx'; import { IonRefresher } from '@ionic/angular'; import { Md5 } from 'ts-md5'; diff --git a/src/core/features/sharedfiles/pages/choose-site/choose-site.ts b/src/core/features/sharedfiles/pages/choose-site/choose-site.ts index a802e1efa..defc4a7bc 100644 --- a/src/core/features/sharedfiles/pages/choose-site/choose-site.ts +++ b/src/core/features/sharedfiles/pages/choose-site/choose-site.ts @@ -14,7 +14,7 @@ import { Component, OnInit } from '@angular/core'; import { CoreSharedFilesHelper } from '@features/sharedfiles/services/sharedfiles-helper'; -import { FileEntry } from '@ionic-native/file'; +import { FileEntry } from '@ionic-native/file/ngx'; import { CoreFile } from '@services/file'; import { CoreNavigator } from '@services/navigator'; import { CoreSiteBasicInfo, CoreSites } from '@services/sites'; diff --git a/src/core/features/sharedfiles/services/sharedfiles-helper.ts b/src/core/features/sharedfiles/services/sharedfiles-helper.ts index 704c0fb9a..6b6f86230 100644 --- a/src/core/features/sharedfiles/services/sharedfiles-helper.ts +++ b/src/core/features/sharedfiles/services/sharedfiles-helper.ts @@ -13,7 +13,7 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { FileEntry } from '@ionic-native/file'; +import { FileEntry } from '@ionic-native/file/ngx'; import { CoreCanceledError } from '@classes/errors/cancelederror'; import { CoreFileUploader } from '@features/fileuploader/services/fileuploader'; diff --git a/src/core/features/sharedfiles/services/sharedfiles.ts b/src/core/features/sharedfiles/services/sharedfiles.ts index a774aea78..8384b6de2 100644 --- a/src/core/features/sharedfiles/services/sharedfiles.ts +++ b/src/core/features/sharedfiles/services/sharedfiles.ts @@ -13,7 +13,7 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { FileEntry, DirectoryEntry } from '@ionic-native/file'; +import { FileEntry, DirectoryEntry } from '@ionic-native/file/ngx'; import { Md5 } from 'ts-md5/dist/md5'; import { SQLiteDB } from '@classes/sqlitedb'; diff --git a/src/core/features/viewer/components/text/text.ts b/src/core/features/viewer/components/text/text.ts index 2a88fdff1..cd72a31f6 100644 --- a/src/core/features/viewer/components/text/text.ts +++ b/src/core/features/viewer/components/text/text.ts @@ -13,10 +13,9 @@ // limitations under the License. import { Component, Input } from '@angular/core'; -import { FileEntry } from '@ionic-native/file/ngx'; +import { CoreFileEntry } from '@services/file-helper'; import { CoreUtils } from '@services/utils/utils'; -import { CoreWSExternalFile } from '@services/ws'; import { ModalController } from '@singletons'; /** @@ -32,7 +31,7 @@ export class CoreViewerTextComponent { @Input() content?: string; // Modal content. @Input() component?: string; // Component to use in format-text. @Input() componentId?: string | number; // Component ID to use in format-text. - @Input() files?: (CoreWSExternalFile | FileEntry)[]; // List of files. + @Input() files?: CoreFileEntry[]; // List of files. @Input() filter?: boolean; // Whether to filter the text. @Input() contextLevel?: string; // The context level. @Input() instanceId?: number; // The instance ID related to the context. diff --git a/src/core/services/file-helper.ts b/src/core/services/file-helper.ts index 426568b15..aa1745388 100644 --- a/src/core/services/file-helper.ts +++ b/src/core/services/file-helper.ts @@ -13,13 +13,13 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { FileEntry } from '@ionic-native/file'; +import { FileEntry } from '@ionic-native/file/ngx'; import { CoreApp } from '@services/app'; import { CoreFile } from '@services/file'; import { CoreFilepool } from '@services/filepool'; import { CoreSites } from '@services/sites'; -import { CoreWS, CoreWSExternalFile } from '@services/ws'; +import { CoreWS, CoreWSFile } from '@services/ws'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreUrlUtils } from '@services/utils/url'; import { CoreUtils } from '@services/utils/utils'; @@ -46,7 +46,7 @@ export class CoreFileHelperProvider { * @return Resolved on success. */ async downloadAndOpenFile( - file: CoreWSExternalFile, + file: CoreWSFile, component?: string, componentId?: string | number, state?: string, @@ -55,7 +55,7 @@ export class CoreFileHelperProvider { ): Promise { siteId = siteId || CoreSites.getCurrentSiteId(); - const fileUrl = file.fileurl; + const fileUrl = CoreFileHelper.getFileUrl(file); const timemodified = this.getFileTimemodified(file); if (!this.isOpenableInApp(file)) { @@ -119,7 +119,7 @@ export class CoreFileHelperProvider { * @return Resolved with the URL to use on success. */ protected async downloadFileIfNeeded( - file: CoreWSExternalFile, + file: CoreWSFile, fileUrl: string, component?: string, componentId?: string | number, @@ -215,7 +215,7 @@ export class CoreFileHelperProvider { componentId?: string | number, timemodified?: number, onProgress?: (event: ProgressEvent) => void, - file?: CoreWSExternalFile, + file?: CoreWSFile, siteId?: string, ): Promise { siteId = siteId || CoreSites.getCurrentSiteId(); @@ -255,10 +255,10 @@ export class CoreFileHelperProvider { * Get the file's URL. * * @param file The file. - * @deprecated since 3.9.5. Get directly the fileurl instead. + * @return File URL. */ - getFileUrl(file: CoreWSExternalFile): string | undefined { - return file.fileurl; + getFileUrl(file: CoreWSFile): string { + return 'fileurl' in file ? file.fileurl : file.url; } /** @@ -266,7 +266,7 @@ export class CoreFileHelperProvider { * * @param file The file. */ - getFileTimemodified(file: CoreWSExternalFile): number { + getFileTimemodified(file: CoreWSFile): number { return file.timemodified || 0; } @@ -286,8 +286,8 @@ export class CoreFileHelperProvider { * @param file The file to check. * @return Whether the file should be opened in browser. */ - shouldOpenInBrowser(file: CoreWSExternalFile): boolean { - if (!file || !file.isexternalfile || !file.mimetype) { + shouldOpenInBrowser(file: CoreWSFile): boolean { + if (!file || !('isexternalfile' in file) || !file.isexternalfile || !file.mimetype) { return false; } @@ -312,7 +312,7 @@ export class CoreFileHelperProvider { * @param files The files to check. * @return Total files size. */ - async getTotalFilesSize(files: (CoreWSExternalFile | FileEntry)[]): Promise { + async getTotalFilesSize(files: CoreFileEntry[]): Promise { let totalSize = 0; for (const file of files) { @@ -328,14 +328,14 @@ export class CoreFileHelperProvider { * @param file The file to check. * @return File size. */ - async getFileSize(file: CoreWSExternalFile | FileEntry): Promise { + async getFileSize(file: CoreFileEntry): Promise { if ('filesize' in file && (file.filesize || file.filesize === 0)) { return file.filesize; } // If it's a remote file. First check if we have the file downloaded since it's more reliable. if ('filename' in file) { - const fileUrl = file.fileurl; + const fileUrl = CoreFileHelper.getFileUrl(file); try { const siteId = CoreSites.getCurrentSiteId(); @@ -422,3 +422,5 @@ export class CoreFileHelperProvider { export const CoreFileHelper = makeSingleton(CoreFileHelperProvider); export type CoreFileHelperOnProgress = (event?: ProgressEvent | { calculating: true }) => void; + +export type CoreFileEntry = CoreWSFile | FileEntry; diff --git a/src/core/services/file-session.ts b/src/core/services/file-session.ts index 6f9caeace..5bdea6efb 100644 --- a/src/core/services/file-session.ts +++ b/src/core/services/file-session.ts @@ -13,10 +13,9 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { FileEntry } from '@ionic-native/file'; +import { CoreFileEntry } from '@services/file-helper'; import { CoreSites } from '@services/sites'; -import { CoreWSExternalFile } from '@services/ws'; import { makeSingleton } from '@singletons'; /** @@ -29,7 +28,7 @@ import { makeSingleton } from '@singletons'; @Injectable({ providedIn: 'root' }) export class CoreFileSessionProvider { - protected files: {[siteId: string]: {[component: string]: {[id: string]: (CoreWSExternalFile | FileEntry)[]}}} = {}; + protected files: {[siteId: string]: {[component: string]: {[id: string]: CoreFileEntry[]}}} = {}; /** * Add a file to the session. @@ -39,7 +38,7 @@ export class CoreFileSessionProvider { * @param file File to add. * @param siteId Site ID. If not defined, current site. */ - addFile(component: string, id: string | number, file: CoreWSExternalFile | FileEntry, siteId?: string): void { + addFile(component: string, id: string | number, file: CoreFileEntry, siteId?: string): void { siteId = siteId || CoreSites.getCurrentSiteId(); this.initFileArea(component, id, siteId); @@ -69,7 +68,7 @@ export class CoreFileSessionProvider { * @param siteId Site ID. If not defined, current site. * @return Array of files in session. */ - getFiles(component: string, id: string | number, siteId?: string): (CoreWSExternalFile | FileEntry)[] { + getFiles(component: string, id: string | number, siteId?: string): CoreFileEntry[] { siteId = siteId || CoreSites.getCurrentSiteId(); if (this.files[siteId] && this.files[siteId][component] && this.files[siteId][component][id]) { return this.files[siteId][component][id]; @@ -107,7 +106,7 @@ export class CoreFileSessionProvider { * @param file File to remove. The instance should be exactly the same as the one stored in session. * @param siteId Site ID. If not defined, current site. */ - removeFile(component: string, id: string | number, file: CoreWSExternalFile | FileEntry, siteId?: string): void { + removeFile(component: string, id: string | number, file: CoreFileEntry, siteId?: string): void { siteId = siteId || CoreSites.getCurrentSiteId(); if (this.files[siteId] && this.files[siteId][component] && this.files[siteId][component][id]) { const position = this.files[siteId][component][id].indexOf(file); @@ -141,7 +140,7 @@ export class CoreFileSessionProvider { * @param newFiles Files to set. * @param siteId Site ID. If not defined, current site. */ - setFiles(component: string, id: string | number, newFiles: (CoreWSExternalFile | FileEntry)[], siteId?: string): void { + setFiles(component: string, id: string | number, newFiles: CoreFileEntry[], siteId?: string): void { siteId = siteId || CoreSites.getCurrentSiteId(); this.initFileArea(component, id, siteId); diff --git a/src/core/services/file.ts b/src/core/services/file.ts index dc09c9bbc..9923d7a46 100644 --- a/src/core/services/file.ts +++ b/src/core/services/file.ts @@ -14,10 +14,9 @@ import { Injectable } from '@angular/core'; -import { FileEntry, DirectoryEntry, Entry, Metadata, IFile } from '@ionic-native/file'; +import { FileEntry, DirectoryEntry, Entry, Metadata, IFile } from '@ionic-native/file/ngx'; import { CoreApp } from '@services/app'; -import { CoreWSExternalFile } from '@services/ws'; import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreTextUtils } from '@services/utils/text'; import { CoreUtils } from '@services/utils/utils'; @@ -26,6 +25,7 @@ import { CoreError } from '@classes/errors/error'; import { CoreLogger } from '@singletons/logger'; import { makeSingleton, File, Zip, Platform, WebView } from '@singletons'; +import { CoreFileEntry } from '@services/file-helper'; /** * Progress event used when writing a file data into a file. @@ -1177,7 +1177,7 @@ export class CoreFileProvider { * @param files List of used files. * @return Promise resolved when done, rejected if failure. */ - async removeUnusedFiles(dirPath: string, files: (CoreWSExternalFile | FileEntry)[]): Promise { + async removeUnusedFiles(dirPath: string, files: CoreFileEntry[]): Promise { // Get the directory contents. try { const contents = await this.getDirectoryContents(dirPath); @@ -1297,7 +1297,7 @@ export class CoreFileProvider { * @param file The file. * @return The file name. */ - getFileName(file: CoreWSExternalFile | FileEntry): string | undefined { + getFileName(file: CoreFileEntry): string | undefined { return CoreUtils.isFileEntry(file) ? file.name : file.filename; } diff --git a/src/core/services/filepool.ts b/src/core/services/filepool.ts index 80739f24b..b203ae787 100644 --- a/src/core/services/filepool.ts +++ b/src/core/services/filepool.ts @@ -20,7 +20,7 @@ import { CoreEventPackageStatusChanged, CoreEvents } from '@singletons/events'; import { CoreFile } from '@services/file'; import { CorePluginFileDelegate } from '@services/plugin-file-delegate'; import { CoreSites } from '@services/sites'; -import { CoreWS, CoreWSExternalFile } from '@services/ws'; +import { CoreWS, CoreWSExternalFile, CoreWSFile } from '@services/ws'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreTextUtils } from '@services/utils/text'; @@ -46,6 +46,7 @@ import { CoreFilepoolQueueEntry, CoreFilepoolQueueDBEntry, } from '@services/database/filepool'; +import { CoreFileHelper } from './file-helper'; /* * Factory for handling downloading files and retrieve downloaded files. @@ -171,7 +172,7 @@ export class CoreFilepoolProvider { */ async addFileLinkByUrl(siteId: string, fileUrl: string, component: string, componentId?: string | number): Promise { const file = await this.fixPluginfileURL(siteId, fileUrl); - const fileId = this.getFileIdByUrl(file.fileurl); + const fileId = this.getFileIdByUrl(CoreFileHelper.getFileUrl(file)); await this.addFileLink(siteId, fileId, component, componentId); } @@ -199,7 +200,7 @@ export class CoreFilepoolProvider { * @param componentId An ID to use in conjunction with the component (optional). * @return Resolved on success. */ - addFilesToQueue(siteId: string, files: CoreWSExternalFile[], component?: string, componentId?: string | number): Promise { + addFilesToQueue(siteId: string, files: CoreWSFile[], component?: string, componentId?: string | number): Promise { return this.downloadOrPrefetchFiles(siteId, files, true, false, component, componentId); } @@ -342,7 +343,7 @@ export class CoreFilepoolProvider { // Fix the URL and use the fixed data. const file = await this.fixPluginfileURL(siteId, fileUrl); - fileUrl = file.fileurl; + fileUrl = CoreFileHelper.getFileUrl(file); timemodified = file.timemodified || timemodified; } @@ -735,7 +736,7 @@ export class CoreFilepoolProvider { */ downloadOrPrefetchFiles( siteId: string, - files: CoreWSExternalFile[], + files: CoreWSFile[], prefetch: boolean, ignoreStale?: boolean, component?: string, @@ -746,11 +747,11 @@ export class CoreFilepoolProvider { // Download files. files.forEach((file) => { - const url = file.fileurl; + const url = CoreFileHelper.getFileUrl(file); const timemodified = file.timemodified; const options = { - isexternalfile: file.isexternalfile, - repositorytype: file.repositorytype, + isexternalfile: 'isexternalfile' in file ? file.isexternalfile : undefined, + repositorytype: 'repositorytype' in file ? file.repositorytype : undefined, }; let path: string | undefined; @@ -799,7 +800,7 @@ export class CoreFilepoolProvider { */ downloadOrPrefetchPackage( siteId: string, - fileList: CoreWSExternalFile[], + fileList: CoreWSFile[], prefetch: boolean, component: string, componentId?: string | number, @@ -822,10 +823,10 @@ export class CoreFilepoolProvider { let packageLoaded = 0; fileList.forEach((file) => { - const fileUrl = file.fileurl; + const fileUrl = CoreFileHelper.getFileUrl(file); const options = { - isexternalfile: file.isexternalfile, - repositorytype: file.repositorytype, + isexternalfile: 'isexternalfile' in file ? file.isexternalfile : undefined, + repositorytype: 'repositorytype' in file ? file.repositorytype : undefined, }; let path: string | undefined; let promise: Promise; @@ -924,7 +925,7 @@ export class CoreFilepoolProvider { */ downloadPackage( siteId: string, - fileList: CoreWSExternalFile[], + fileList: CoreWSFile[], component: string, componentId?: string | number, extra?: string, @@ -973,7 +974,7 @@ export class CoreFilepoolProvider { } const file = await this.fixPluginfileURL(siteId, fileUrl); - fileUrl = file.fileurl; + fileUrl = CoreFileHelper.getFileUrl(file); timemodified = file.timemodified || timemodified; options = Object.assign({}, options); // Create a copy to prevent modifying the original object. @@ -1158,11 +1159,15 @@ export class CoreFilepoolProvider { * @param timemodified The timemodified of the file. * @return Promise resolved with the file data to use. */ - protected async fixPluginfileURL(siteId: string, fileUrl: string, timemodified: number = 0): Promise { + protected async fixPluginfileURL(siteId: string, fileUrl: string, timemodified: number = 0): Promise { const file = await CorePluginFileDelegate.getDownloadableFile({ fileurl: fileUrl, timemodified }); const site = await CoreSites.getSite(siteId); - file.fileurl = await site.checkAndFixPluginfileURL(file.fileurl); + if ('fileurl' in file) { + file.fileurl = await site.checkAndFixPluginfileURL(file.fileurl); + } else { + file.url = await site.checkAndFixPluginfileURL(file.url); + } return file; } @@ -1206,7 +1211,7 @@ export class CoreFilepoolProvider { } const file = await this.fixPluginfileURL(siteId, fileUrl); - const fileId = this.getFileIdByUrl(file.fileurl); + const fileId = this.getFileIdByUrl(CoreFileHelper.getFileUrl(file)); const filePath = await this.getFilePath(siteId, fileId, ''); const dirEntry = await CoreFile.getDir(filePath); @@ -1244,7 +1249,7 @@ export class CoreFilepoolProvider { */ getFileEventNameByUrl(siteId: string, fileUrl: string): Promise { return this.fixPluginfileURL(siteId, fileUrl).then((file) => { - const fileId = this.getFileIdByUrl(file.fileurl); + const fileId = this.getFileIdByUrl(CoreFileHelper.getFileUrl(file)); return this.getFileEventName(siteId, fileId); }); @@ -1342,7 +1347,7 @@ export class CoreFilepoolProvider { */ async getFilePathByUrl(siteId: string, fileUrl: string): Promise { const file = await this.fixPluginfileURL(siteId, fileUrl); - const fileId = this.getFileIdByUrl(file.fileurl); + const fileId = this.getFileIdByUrl(CoreFileHelper.getFileUrl(file)); return this.getFilePath(siteId, fileId); } @@ -1433,7 +1438,7 @@ export class CoreFilepoolProvider { filePath?: string, revision?: number, ): Promise { - let file: CoreWSExternalFile; + let file: CoreWSFile; try { file = await this.fixPluginfileURL(siteId, fileUrl, timemodified); @@ -1441,7 +1446,7 @@ export class CoreFilepoolProvider { return CoreConstants.NOT_DOWNLOADABLE; } - fileUrl = file.fileurl; + fileUrl = CoreFileHelper.getFileUrl(file); timemodified = file.timemodified || timemodified; revision = revision || this.getRevisionFromUrl(fileUrl); const fileId = this.getFileIdByUrl(fileUrl); @@ -1527,7 +1532,7 @@ export class CoreFilepoolProvider { const file = await this.fixPluginfileURL(siteId, fileUrl, timemodified); - fileUrl = file.fileurl; + fileUrl = CoreFileHelper.getFileUrl(file); timemodified = file.timemodified || timemodified; revision = revision || this.getRevisionFromUrl(fileUrl); const fileId = this.getFileIdByUrl(fileUrl); @@ -1635,7 +1640,7 @@ export class CoreFilepoolProvider { } const file = await this.fixPluginfileURL(siteId, fileUrl); - const fileId = this.getFileIdByUrl(file.fileurl); + const fileId = this.getFileIdByUrl(CoreFileHelper.getFileUrl(file)); return this.getInternalUrlById(siteId, fileId); } @@ -1693,7 +1698,7 @@ export class CoreFilepoolProvider { */ getPackageDirPathByUrl(siteId: string, url: string): Promise { return this.fixPluginfileURL(siteId, url).then((file) => { - const dirName = this.getPackageDirNameByUrl(file.fileurl); + const dirName = this.getPackageDirNameByUrl(CoreFileHelper.getFileUrl(file)); return this.getFilePath(siteId, dirName, ''); }); @@ -1712,7 +1717,7 @@ export class CoreFilepoolProvider { } const file = await this.fixPluginfileURL(siteId, url); - const dirName = this.getPackageDirNameByUrl(file.fileurl); + const dirName = this.getPackageDirNameByUrl(CoreFileHelper.getFileUrl(file)); const dirPath = await this.getFilePath(siteId, dirName, ''); const dirEntry = await CoreFile.getDir(dirPath); @@ -1890,12 +1895,14 @@ export class CoreFilepoolProvider { * @param files Package files. * @return Highest revision. */ - getRevisionFromFileList(files: CoreWSExternalFile[]): number { + getRevisionFromFileList(files: CoreWSFile[]): number { let revision = 0; files.forEach((file) => { - if (file.fileurl) { - const r = this.getRevisionFromUrl(file.fileurl); + const fileUrl = CoreFileHelper.getFileUrl(file); + + if (fileUrl) { + const r = this.getRevisionFromUrl(fileUrl); if (r > revision) { revision = r; } @@ -1981,7 +1988,7 @@ export class CoreFilepoolProvider { * @param files List of files. * @return Time modified. */ - getTimemodifiedFromFileList(files: CoreWSExternalFile[]): number { + getTimemodifiedFromFileList(files: CoreWSFile[]): number { let timemodified = 0; files.forEach((file) => { @@ -2163,7 +2170,7 @@ export class CoreFilepoolProvider { */ async invalidateFileByUrl(siteId: string, fileUrl: string): Promise { const file = await this.fixPluginfileURL(siteId, fileUrl); - const fileId = this.getFileIdByUrl(file.fileurl); + const fileId = this.getFileIdByUrl(CoreFileHelper.getFileUrl(file)); const db = await CoreSites.getSiteDb(siteId); @@ -2250,7 +2257,7 @@ export class CoreFilepoolProvider { */ async isFileDownloadingByUrl(siteId: string, fileUrl: string): Promise { const file = await this.fixPluginfileURL(siteId, fileUrl); - const fileId = this.getFileIdByUrl(file.fileurl); + const fileId = this.getFileIdByUrl(CoreFileHelper.getFileUrl(file)); await this.hasFileInQueue(siteId, fileId); } @@ -2403,7 +2410,7 @@ export class CoreFilepoolProvider { */ prefetchPackage( siteId: string, - fileList: CoreWSExternalFile[], + fileList: CoreWSFile[], component: string, componentId?: string | number, extra?: string, @@ -2691,7 +2698,7 @@ export class CoreFilepoolProvider { */ async removeFileByUrl(siteId: string, fileUrl: string): Promise { const file = await this.fixPluginfileURL(siteId, fileUrl); - const fileId = this.getFileIdByUrl(file.fileurl); + const fileId = this.getFileIdByUrl(CoreFileHelper.getFileUrl(file)); await this.removeFileById(siteId, fileId); } diff --git a/src/core/services/plugin-file-delegate.ts b/src/core/services/plugin-file-delegate.ts index 425c67e6e..944278ee6 100644 --- a/src/core/services/plugin-file-delegate.ts +++ b/src/core/services/plugin-file-delegate.ts @@ -13,14 +13,15 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { FileEntry } from '@ionic-native/file'; +import { FileEntry } from '@ionic-native/file/ngx'; import { CoreFilepool, CoreFilepoolOnProgressCallback } from '@services/filepool'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { CoreConstants } from '@/core/constants'; import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate'; import { makeSingleton } from '@singletons'; import { CoreSites } from './sites'; +import { CoreFileHelper } from './file-helper'; /** * Delegate to register pluginfile information handlers. @@ -57,7 +58,7 @@ export class CorePluginFileDelegateService extends CoreDelegate { + getDownloadableFile(file: CoreWSFile, siteId?: string): Promise { const handler = this.getHandlerForFile(file); return this.getHandlerDownloadableFile(file, handler, siteId); @@ -72,10 +73,10 @@ export class CorePluginFileDelegateService extends CoreDelegate { + ): Promise { const isDownloadable = await this.isFileDownloadable(file, siteId); if (!isDownloadable.downloadable) { @@ -134,13 +135,13 @@ export class CorePluginFileDelegateService extends CoreDelegate { + async getFilesDownloadSize(files: CoreWSFile[], siteId?: string): Promise { siteId = siteId || CoreSites.getCurrentSiteId(); - const filteredFiles = []; + const filteredFiles = []; await Promise.all(files.map(async (file) => { - const state = await CoreFilepool.getFileStateByUrl(siteId!, file.fileurl, file.timemodified); + const state = await CoreFilepool.getFileStateByUrl(siteId!, CoreFileHelper.getFileUrl(file), file.timemodified); if (state != CoreConstants.DOWNLOADED && state != CoreConstants.NOT_DOWNLOADABLE) { filteredFiles.push(file); @@ -157,7 +158,7 @@ export class CorePluginFileDelegateService extends CoreDelegate { + async getFilesSize(files: CoreWSFile[], siteId?: string): Promise { const result = { size: 0, total: true, @@ -184,7 +185,7 @@ export class CorePluginFileDelegateService extends CoreDelegate { + async getFileSize(file: CoreWSFile, siteId?: string): Promise { const isDownloadable = await this.isFileDownloadable(file, siteId); if (!isDownloadable.downloadable) { @@ -218,7 +219,7 @@ export class CorePluginFileDelegateService extends CoreDelegate { + async isFileDownloadable(file: CoreWSFile, siteId?: string): Promise { const handler = this.getHandlerForFile(file); if (handler && handler.isFileDownloadable) { @@ -337,7 +338,7 @@ export interface CorePluginFileHandler extends CoreDelegateHandler { * @param siteId Site ID. If not defined, current site. * @return Promise resolved with the file to use. Rejected if cannot download. */ - getDownloadableFile?(file: CoreWSExternalFile, siteId?: string): Promise; + getDownloadableFile?(file: CoreWSFile, siteId?: string): Promise; /** * Given an HTML element, get the URLs of the files that should be downloaded and weren't treated by @@ -355,7 +356,7 @@ export interface CorePluginFileHandler extends CoreDelegateHandler { * @param siteId Site ID. If not defined, current site. * @return Promise resolved with the size. */ - getFileSize?(file: CoreWSExternalFile, siteId?: string): Promise; + getFileSize?(file: CoreWSFile, siteId?: string): Promise; /** * Check if a file is downloadable. @@ -364,7 +365,7 @@ export interface CorePluginFileHandler extends CoreDelegateHandler { * @param siteId Site ID. If not defined, current site. * @return Promise resolved with a boolean and a reason why it isn't downloadable if needed. */ - isFileDownloadable?(file: CoreWSExternalFile, siteId?: string): Promise; + isFileDownloadable?(file: CoreWSFile, siteId?: string): Promise; /** * Check whether the file should be treated by this handler. It is used in functions where the component isn't used. @@ -372,7 +373,7 @@ export interface CorePluginFileHandler extends CoreDelegateHandler { * @param file The file data. * @return Whether the file should be treated by this handler. */ - shouldHandleFile?(file: CoreWSExternalFile): boolean; + shouldHandleFile?(file: CoreWSFile): boolean; /** * Treat a downloaded file. diff --git a/src/core/services/utils/mimetype.ts b/src/core/services/utils/mimetype.ts index 3296d5d43..92ec8ab48 100644 --- a/src/core/services/utils/mimetype.ts +++ b/src/core/services/utils/mimetype.ts @@ -13,17 +13,18 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { FileEntry } from '@ionic-native/file'; +import { FileEntry } from '@ionic-native/file/ngx'; import { CoreFile } from '@services/file'; import { CoreTextUtils } from '@services/utils/text'; import { makeSingleton, Translate } from '@singletons'; import { CoreLogger } from '@singletons/logger'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { CoreUtils } from '@services/utils/utils'; import extToMime from '@/assets/exttomime.json'; import mimeToExt from '@/assets/mimetoext.json'; +import { CoreFileEntry, CoreFileHelper } from '@services/file-helper'; interface MimeTypeInfo { type: string; @@ -163,7 +164,7 @@ export class CoreMimetypeUtilsProvider { * @param file File object. * @param path Alternative path that will override fileurl from file object. */ - getEmbeddedHtml(file: CoreWSExternalFile | FileEntry, path?: string): string { + getEmbeddedHtml(file: CoreFileEntry, path?: string): string { const filename = CoreUtils.isFileEntry(file) ? (file as FileEntry).name : file.filename; const extension = !CoreUtils.isFileEntry(file) && file.mimetype ? this.getExtension(file.mimetype) @@ -173,7 +174,7 @@ export class CoreMimetypeUtilsProvider { : (extension && this.getMimeType(extension)); // @todo linting: See if this can be removed - (file as CoreWSExternalFile).mimetype = mimeType; + (file as CoreWSFile).mimetype = mimeType; if (extension && this.canBeEmbedded(extension)) { const embedType = this.getExtensionType(extension); @@ -181,7 +182,7 @@ export class CoreMimetypeUtilsProvider { // @todo linting: See if this can be removed (file as { embedType?: string }).embedType = embedType; - path = path ?? (CoreUtils.isFileEntry(file) ? file.toURL() : file.fileurl); + path = path ?? (CoreUtils.isFileEntry(file) ? file.toURL() : CoreFileHelper.getFileUrl(file)); path = path && CoreFile.convertFileSrc(path); switch (embedType) { @@ -401,7 +402,7 @@ export class CoreMimetypeUtilsProvider { * @param capitalise If true, capitalises first character of result. * @return Type description. */ - getMimetypeDescription(obj: FileEntry | CoreWSExternalFile | string, capitalise?: boolean): string { + getMimetypeDescription(obj: CoreFileEntry | string, capitalise?: boolean): string { const langPrefix = 'assets.mimetypes.'; let filename: string | undefined = ''; let mimetype: string | undefined = ''; diff --git a/src/core/services/utils/text.ts b/src/core/services/utils/text.ts index 34682af36..a7f8013ca 100644 --- a/src/core/services/utils/text.ts +++ b/src/core/services/utils/text.ts @@ -20,9 +20,10 @@ import { CoreApp } from '@services/app'; import { CoreLang } from '@services/lang'; import { CoreAnyError, CoreError } from '@classes/errors/error'; import { makeSingleton, ModalController, Translate } from '@singletons'; -import { CoreWSExternalFile } from '@services/ws'; +import { CoreWSFile } from '@services/ws'; import { Locutus } from '@singletons/locutus'; import { CoreViewerTextComponent } from '@features/viewer/components/text/text'; +import { CoreFileHelper } from '@services/file-helper'; /** * Different type of errors the app can treat. @@ -462,7 +463,7 @@ export class CoreTextUtilsProvider { text: string, component?: string, componentId?: string | number, - files?: CoreWSExternalFile[], + files?: CoreWSFile[], filter?: boolean, contextLevel?: string, instanceId?: number, @@ -555,9 +556,9 @@ export class CoreTextUtilsProvider { * @param files Files to extract the URL from. They need to have the URL in a 'url' or 'fileurl' attribute. * @return Pluginfile URL, undefined if no files found. */ - getTextPluginfileUrl(files: CoreWSExternalFile[]): string | undefined { + getTextPluginfileUrl(files: CoreWSFile[]): string | undefined { if (files?.length) { - const url = files[0].fileurl; + const url = CoreFileHelper.getFileUrl(files[0]); // Remove text after last slash (encoded or not). return url?.substr(0, Math.max(url.lastIndexOf('/'), url.lastIndexOf('%2F'))); @@ -759,7 +760,7 @@ export class CoreTextUtilsProvider { replaceDraftfileUrls( siteUrl: string, text: string, - files: CoreWSExternalFile[], + files: CoreWSFile[], ): { text: string; replaceMap?: {[url: string]: string} } { if (!text || !files || !files.length) { @@ -776,7 +777,7 @@ export class CoreTextUtilsProvider { // Index the pluginfile URLs by file name. const pluginfileMap: {[name: string]: string} = {}; files.forEach((file) => { - pluginfileMap[file.filename!] = file.fileurl; + pluginfileMap[file.filename!] = CoreFileHelper.getFileUrl(file); }); // Replace each draftfile with the corresponding pluginfile URL. @@ -812,7 +813,7 @@ export class CoreTextUtilsProvider { * @param files Files to extract the pluginfile URL from. They need to have the URL in a url or fileurl attribute. * @return Treated text. */ - replacePluginfileUrls(text: string, files: CoreWSExternalFile[]): string { + replacePluginfileUrls(text: string, files: CoreWSFile[]): string { if (text && typeof text == 'string') { const fileURL = this.getTextPluginfileUrl(files); if (fileURL) { @@ -830,7 +831,7 @@ export class CoreTextUtilsProvider { * @param replaceMap Map of the replacements that were done. * @return Treated text. */ - restoreDraftfileUrls(siteUrl: string, treatedText: string, originalText: string, files: CoreWSExternalFile[]): string { + restoreDraftfileUrls(siteUrl: string, treatedText: string, originalText: string, files: CoreWSFile[]): string { if (!treatedText || !files || !files.length) { return treatedText; } @@ -848,7 +849,7 @@ export class CoreTextUtilsProvider { return; // Original URL not found, skip. } - treatedText = treatedText.replace(new RegExp(this.escapeForRegex(file.fileurl), 'g'), matches[0]); + treatedText = treatedText.replace(new RegExp(this.escapeForRegex(CoreFileHelper.getFileUrl(file)), 'g'), matches[0]); }); return treatedText; @@ -861,7 +862,7 @@ export class CoreTextUtilsProvider { * @param files Files to extract the pluginfile URL from. They need to have the URL in a url or fileurl attribute. * @return Treated text. */ - restorePluginfileUrls(text: string, files: CoreWSExternalFile[]): string { + restorePluginfileUrls(text: string, files: CoreWSFile[]): string { if (text && typeof text == 'string') { const fileURL = this.getTextPluginfileUrl(files); if (fileURL) { @@ -1103,7 +1104,7 @@ export class CoreTextUtilsProvider { export type CoreTextUtilsViewTextOptions = { component?: string; // Component to link the embedded files to. componentId?: string | number; // An ID to use in conjunction with the component. - files?: CoreWSExternalFile[]; // List of files to display along with the text. + files?: CoreWSFile[]; // List of files to display along with the text. filter?: boolean; // Whether the text should be filtered. contextLevel?: string; // The context level. instanceId?: number; // The instance ID related to the context. diff --git a/src/core/services/utils/utils.ts b/src/core/services/utils/utils.ts index bf83806e2..4e0ddb726 100644 --- a/src/core/services/utils/utils.ts +++ b/src/core/services/utils/utils.ts @@ -14,14 +14,14 @@ import { Injectable, NgZone } from '@angular/core'; import { InAppBrowserObject, InAppBrowserOptions } from '@ionic-native/in-app-browser'; -import { FileEntry } from '@ionic-native/file'; +import { FileEntry } from '@ionic-native/file/ngx'; import { Subscription } from 'rxjs'; import { CoreApp } from '@services/app'; import { CoreEvents } from '@singletons/events'; import { CoreFile } from '@services/file'; import { CoreLang } from '@services/lang'; -import { CoreWS, CoreWSExternalFile } from '@services/ws'; +import { CoreWS, CoreWSFile } from '@services/ws'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreTextUtils } from '@services/utils/text'; @@ -31,6 +31,7 @@ import { CoreLogger } from '@singletons/logger'; import { CoreFileSizeSum } from '@services/plugin-file-delegate'; import { CoreViewerQRScannerComponent } from '@features/viewer/components/qr-scanner/qr-scanner'; import { CoreCanceledError } from '@classes/errors/cancelederror'; +import { CoreFileEntry } from '@services/file-helper'; type TreeNode = T & { children: TreeNode[] }; @@ -379,11 +380,7 @@ export class CoreUtilsProvider { /** * Execute promises one depending on the previous. * - * @param orderedPromisesData Data to be executed including the following values: - * - func: Function to be executed. - * - context: Context to pass to the function. This allows using "this" inside the function. - * - params: Array of data to be sent to the function. - * - blocking: Boolean. If promise should block the following. + * @param orderedPromisesData Data to be executed. * @return Promise resolved when all promises are resolved. */ executeOrderedPromises(orderedPromisesData: OrderedPromiseData[]): Promise { @@ -748,7 +745,7 @@ export class CoreUtilsProvider { * @param file File. * @return Type guard indicating if the file is a FileEntry. */ - isFileEntry(file: FileEntry | CoreWSExternalFile): file is FileEntry { + isFileEntry(file: CoreFileEntry): file is FileEntry { return 'isFile' in file; } @@ -768,7 +765,7 @@ export class CoreUtilsProvider { * @param files List of files. * @return String with error message if repeated, false if no repeated. */ - hasRepeatedFilenames(files: (FileEntry | CoreWSExternalFile)[]): string | false { + hasRepeatedFilenames(files: CoreFileEntry[]): string | false { if (!files || !files.length) { return false; } @@ -1368,7 +1365,7 @@ export class CoreUtilsProvider { * @return File size and a boolean to indicate if it is the total size or only partial. * @deprecated since 3.8.0. Use CorePluginFileDelegate.getFilesSize instead. */ - sumFileSizes(files: CoreWSExternalFile[]): CoreFileSizeSum { + sumFileSizes(files: CoreWSFile[]): CoreFileSizeSum { const result = { size: 0, total: true, diff --git a/src/core/services/ws.ts b/src/core/services/ws.ts index 912cd65e9..13992fb2a 100644 --- a/src/core/services/ws.ts +++ b/src/core/services/ws.ts @@ -15,7 +15,7 @@ import { Injectable } from '@angular/core'; import { HttpResponse, HttpParams } from '@angular/common/http'; -import { FileEntry } from '@ionic-native/file'; +import { FileEntry } from '@ionic-native/file/ngx'; import { FileUploadOptions } from '@ionic-native/file-transfer/ngx'; import { Md5 } from 'ts-md5/dist/md5'; import { Observable } from 'rxjs'; @@ -1087,6 +1087,43 @@ export type CoreWSExternalFile = { repositorytype?: string; // The repository type for external files. }; +/** + * Structure of files returned by stored_file_exporter. + */ +export type CoreWSStoredFile = { + contextid: number; // Contextid. + component: string; // Component. + filearea: string; // Filearea. + itemid: number; // Itemid. + filepath: string; // Filepath. + filename: string; // Filename. + isdir: boolean; // Isdir. + isimage: boolean; // Isimage. + timemodified: number; // Timemodified. + timecreated: number; // Timecreated. + filesize: number; // Filesize. + author: string; // Author. + license: string; // License. + filenameshort: string; // Filenameshort. + filesizeformatted: string; // Filesizeformatted. + icon: string; // Icon. + timecreatedformatted: string; // Timecreatedformatted. + timemodifiedformatted: string; // Timemodifiedformatted. + url: string; // Url. + urls: { + export?: string; // The URL used to export the attachment. + }; + html: { + plagiarism?: string; // The HTML source for the Plagiarism Response. + }; + mimetype: undefined; // File mimetype. @todo Not implemented yet in Moodle, see MDL-71354. +}; + +/** + * Common file structures returned by WS. + */ +export type CoreWSFile = CoreWSExternalFile | CoreWSStoredFile; + /** * Data returned by date_exporter. */