MOBILE-3641 core: Support CoreWSStoredFile in the whole app

main
Dani Palou 2021-04-16 15:15:21 +02:00
parent 6a846488ee
commit 163647b165
87 changed files with 410 additions and 394 deletions

View File

@ -24,7 +24,7 @@ import { CoreCourseUserAdminOrNavOptionIndexed } from '@features/courses/service
import { CoreEnrolledCourseDataWithExtraInfoAndOptions } from '@features/courses/services/courses-helper'; import { CoreEnrolledCourseDataWithExtraInfoAndOptions } from '@features/courses/services/courses-helper';
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { AddonBlog } from '../blog'; import { AddonBlog } from '../blog';
import { AddonBlogMainMenuHandlerService } from './mainmenu'; import { AddonBlogMainMenuHandlerService } from './mainmenu';
@ -89,7 +89,7 @@ export class AddonBlogCourseOptionHandlerService implements CoreCourseOptionsHan
const result = await AddonBlog.getEntries({ courseid: course.id }); const result = await AddonBlog.getEntries({ courseid: course.id });
await Promise.all(result.entries.map(async (entry) => { await Promise.all(result.entries.map(async (entry) => {
let files: CoreWSExternalFile[] = []; let files: CoreWSFile[] = [];
if (entry.attachmentfiles && entry.attachmentfiles.length) { if (entry.attachmentfiles && entry.attachmentfiles.length) {
files = entry.attachmentfiles; files = entry.attachmentfiles;

View File

@ -15,7 +15,7 @@
import { Component, Input, OnInit, ViewChild, Type } from '@angular/core'; import { Component, Input, OnInit, ViewChild, Type } from '@angular/core';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
import { CoreDynamicComponent } from '@components/dynamic-component/dynamic-component'; import { CoreDynamicComponent } from '@components/dynamic-component/dynamic-component';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { ModalController } from '@singletons'; import { ModalController } from '@singletons';
import { AddonModAssignFeedbackCommentsTextData } from '../../feedback/comments/services/handler'; import { AddonModAssignFeedbackCommentsTextData } from '../../feedback/comments/services/handler';
import { import {
@ -53,7 +53,7 @@ export class AddonModAssignFeedbackPluginComponent implements OnInit {
// Data to render the plugin if it isn't supported. // Data to render the plugin if it isn't supported.
component = AddonModAssignProvider.COMPONENT; component = AddonModAssignProvider.COMPONENT;
text = ''; text = '';
files: CoreWSExternalFile[] = []; files: CoreWSFile[] = [];
notSupported = false; notSupported = false;
pluginLoaded = false; pluginLoaded = false;

View File

@ -14,7 +14,6 @@
import { Component, Input, OnInit, Type, ViewChild } from '@angular/core'; import { Component, Input, OnInit, Type, ViewChild } from '@angular/core';
import { CoreDynamicComponent } from '@components/dynamic-component/dynamic-component'; import { CoreDynamicComponent } from '@components/dynamic-component/dynamic-component';
import { CoreWSExternalFile } from '@services/ws';
import { import {
AddonModAssignAssign, AddonModAssignAssign,
AddonModAssignSubmission, AddonModAssignSubmission,
@ -24,7 +23,7 @@ import {
} from '../../services/assign'; } from '../../services/assign';
import { AddonModAssignHelper, AddonModAssignPluginConfig } from '../../services/assign-helper'; import { AddonModAssignHelper, AddonModAssignPluginConfig } from '../../services/assign-helper';
import { AddonModAssignSubmissionDelegate } from '../../services/submission-delegate'; 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. * 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. // Data to render the plugin if it isn't supported.
component = AddonModAssignProvider.COMPONENT; component = AddonModAssignProvider.COMPONENT;
text = ''; text = '';
files: (FileEntry | CoreWSExternalFile)[] = []; files: CoreFileEntry[] = [];
notSupported = false; notSupported = false;
pluginLoaded = false; pluginLoaded = false;

View File

@ -25,7 +25,7 @@ import { Injectable, Type } from '@angular/core';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { AddonModAssignFeedbackCommentsComponent } from '../component/comments'; import { AddonModAssignFeedbackCommentsComponent } from '../component/comments';
@ -126,7 +126,7 @@ export class AddonModAssignFeedbackCommentsHandlerService implements AddonModAss
assign: AddonModAssignAssign, assign: AddonModAssignAssign,
submission: AddonModAssignSubmission, submission: AddonModAssignSubmission,
plugin: AddonModAssignPlugin, plugin: AddonModAssignPlugin,
): CoreWSExternalFile[] { ): CoreWSFile[] {
return AddonModAssign.getSubmissionPluginAttachments(plugin); return AddonModAssign.getSubmissionPluginAttachments(plugin);
} }

View File

@ -15,7 +15,7 @@
import { AddonModAssignFeedbackPluginComponent } from '@addons/mod/assign/components/feedback-plugin/feedback-plugin'; import { AddonModAssignFeedbackPluginComponent } from '@addons/mod/assign/components/feedback-plugin/feedback-plugin';
import { AddonModAssignProvider, AddonModAssign } from '@addons/mod/assign/services/assign'; import { AddonModAssignProvider, AddonModAssign } from '@addons/mod/assign/services/assign';
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
/** /**
* Component to render a edit pdf feedback plugin. * Component to render a edit pdf feedback plugin.
@ -27,7 +27,7 @@ import { CoreWSExternalFile } from '@services/ws';
export class AddonModAssignFeedbackEditPdfComponent extends AddonModAssignFeedbackPluginComponent implements OnInit { export class AddonModAssignFeedbackEditPdfComponent extends AddonModAssignFeedbackPluginComponent implements OnInit {
component = AddonModAssignProvider.COMPONENT; component = AddonModAssignProvider.COMPONENT;
files: CoreWSExternalFile[] = []; files: CoreWSFile[] = [];
/** /**
* Component being initialized. * Component being initialized.

View File

@ -20,7 +20,7 @@ import {
} from '@addons/mod/assign/services/assign'; } from '@addons/mod/assign/services/assign';
import { AddonModAssignFeedbackHandler } from '@addons/mod/assign/services/feedback-delegate'; import { AddonModAssignFeedbackHandler } from '@addons/mod/assign/services/feedback-delegate';
import { Injectable, Type } from '@angular/core'; import { Injectable, Type } from '@angular/core';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { AddonModAssignFeedbackEditPdfComponent } from '../component/editpdf'; import { AddonModAssignFeedbackEditPdfComponent } from '../component/editpdf';
@ -56,7 +56,7 @@ export class AddonModAssignFeedbackEditPdfHandlerService implements AddonModAssi
assign: AddonModAssignAssign, assign: AddonModAssignAssign,
submission: AddonModAssignSubmission, submission: AddonModAssignSubmission,
plugin: AddonModAssignPlugin, plugin: AddonModAssignPlugin,
): CoreWSExternalFile[] { ): CoreWSFile[] {
return AddonModAssign.getSubmissionPluginAttachments(plugin); return AddonModAssign.getSubmissionPluginAttachments(plugin);
} }

View File

@ -15,7 +15,7 @@
import { AddonModAssignFeedbackPluginComponent } from '@addons/mod/assign/components/feedback-plugin/feedback-plugin'; import { AddonModAssignFeedbackPluginComponent } from '@addons/mod/assign/components/feedback-plugin/feedback-plugin';
import { AddonModAssign, AddonModAssignProvider } from '@addons/mod/assign/services/assign'; import { AddonModAssign, AddonModAssignProvider } from '@addons/mod/assign/services/assign';
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
/** /**
* Component to render a file feedback plugin. * Component to render a file feedback plugin.
@ -27,7 +27,7 @@ import { CoreWSExternalFile } from '@services/ws';
export class AddonModAssignFeedbackFileComponent extends AddonModAssignFeedbackPluginComponent implements OnInit { export class AddonModAssignFeedbackFileComponent extends AddonModAssignFeedbackPluginComponent implements OnInit {
component = AddonModAssignProvider.COMPONENT; component = AddonModAssignProvider.COMPONENT;
files: CoreWSExternalFile[] = []; files: CoreWSFile[] = [];
/** /**
* Component being initialized. * Component being initialized.

View File

@ -20,7 +20,7 @@ import {
} from '@addons/mod/assign/services/assign'; } from '@addons/mod/assign/services/assign';
import { AddonModAssignFeedbackHandler } from '@addons/mod/assign/services/feedback-delegate'; import { AddonModAssignFeedbackHandler } from '@addons/mod/assign/services/feedback-delegate';
import { Injectable, Type } from '@angular/core'; import { Injectable, Type } from '@angular/core';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { AddonModAssignFeedbackFileComponent } from '../component/file'; import { AddonModAssignFeedbackFileComponent } from '../component/file';
@ -56,7 +56,7 @@ export class AddonModAssignFeedbackFileHandlerService implements AddonModAssignF
assign: AddonModAssignAssign, assign: AddonModAssignAssign,
submission: AddonModAssignSubmission, submission: AddonModAssignSubmission,
plugin: AddonModAssignPlugin, plugin: AddonModAssignPlugin,
): CoreWSExternalFile[] { ): CoreWSFile[] {
return AddonModAssign.getSubmissionPluginAttachments(plugin); return AddonModAssign.getSubmissionPluginAttachments(plugin);
} }

View File

@ -15,7 +15,6 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreFileUploader, CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader'; import { CoreFileUploader, CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader';
import { CoreSites, CoreSitesCommonWSOptions } from '@services/sites'; import { CoreSites, CoreSitesCommonWSOptions } from '@services/sites';
import { CoreWSExternalFile } from '@services/ws';
import { FileEntry } from '@ionic-native/file/ngx'; import { FileEntry } from '@ionic-native/file/ngx';
import { import {
AddonModAssignProvider, AddonModAssignProvider,
@ -36,6 +35,7 @@ import { AddonModAssignSubmissionDelegate } from './submission-delegate';
import { AddonModAssignFeedbackDelegate } from './feedback-delegate'; import { AddonModAssignFeedbackDelegate } from './feedback-delegate';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { CoreFormFields } from '@singletons/form'; import { CoreFormFields } from '@singletons/form';
import { CoreFileEntry } from '@services/file-helper';
/** /**
* Service that provides some helper functions for assign. * Service that provides some helper functions for assign.
@ -642,7 +642,7 @@ export class AddonModAssignHelperProvider {
async storeSubmissionFiles( async storeSubmissionFiles(
assignId: number, assignId: number,
folderName: string, folderName: string,
files: (CoreWSExternalFile | FileEntry)[], files: CoreFileEntry[],
userId?: number, userId?: number,
siteId?: string, siteId?: string,
): Promise<CoreFileUploaderStoreFilesResult> { ): Promise<CoreFileUploaderStoreFilesResult> {
@ -661,7 +661,7 @@ export class AddonModAssignHelperProvider {
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @return Promise resolved with the itemId. * @return Promise resolved with the itemId.
*/ */
uploadFile(assignId: number, file: CoreWSExternalFile | FileEntry, itemId?: number, siteId?: string): Promise<number> { uploadFile(assignId: number, file: CoreFileEntry, itemId?: number, siteId?: string): Promise<number> {
return CoreFileUploader.uploadOrReuploadFile(file, itemId, AddonModAssignProvider.COMPONENT, assignId, siteId); 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. * @param siteId Site ID. If not defined, current site.
* @return Promise resolved with the itemId. * @return Promise resolved with the itemId.
*/ */
uploadFiles(assignId: number, files: (CoreWSExternalFile | FileEntry)[], siteId?: string): Promise<number> { uploadFiles(assignId: number, files: CoreFileEntry[], siteId?: string): Promise<number> {
return CoreFileUploader.uploadOrReuploadFiles(files, AddonModAssignProvider.COMPONENT, assignId, siteId); return CoreFileUploader.uploadOrReuploadFiles(files, AddonModAssignProvider.COMPONENT, assignId, siteId);
} }
@ -693,7 +693,7 @@ export class AddonModAssignHelperProvider {
async uploadOrStoreFiles( async uploadOrStoreFiles(
assignId: number, assignId: number,
folderName: string, folderName: string,
files: (CoreWSExternalFile | FileEntry)[], files: CoreFileEntry[],
offline = false, offline = false,
userId?: number, userId?: number,
siteId?: string, siteId?: string,

View File

@ -53,7 +53,7 @@ export class AddonModAssignSyncProvider extends CoreCourseActivitySyncBaseProvid
protected componentTranslatableString = 'assign'; protected componentTranslatableString = 'assign';
constructor() { constructor() {
super('AddonModLessonSyncProvider'); super('AddonModAssignSyncProvider');
} }
/** /**

View File

@ -16,7 +16,7 @@ import { Injectable } from '@angular/core';
import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites';
import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; import { CoreSite, CoreSiteWSPreSets } from '@classes/site';
import { CoreInterceptor } from '@classes/interceptor'; import { CoreInterceptor } from '@classes/interceptor';
import { CoreWSExternalWarning, CoreWSExternalFile } from '@services/ws'; import { CoreWSExternalWarning, CoreWSExternalFile, CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { CoreCourseCommonModWSOptions } from '@features/course/services/course';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
@ -405,12 +405,12 @@ export class AddonModAssignProvider {
* @param submissionPlugin Submission plugin. * @param submissionPlugin Submission plugin.
* @return Submission plugin attachments. * @return Submission plugin attachments.
*/ */
getSubmissionPluginAttachments(submissionPlugin: AddonModAssignPlugin): CoreWSExternalFile[] { getSubmissionPluginAttachments(submissionPlugin: AddonModAssignPlugin): CoreWSFile[] {
if (!submissionPlugin.fileareas) { if (!submissionPlugin.fileareas) {
return []; return [];
} }
const files: CoreWSExternalFile[] = []; const files: CoreWSFile[] = [];
submissionPlugin.fileareas.forEach((filearea) => { submissionPlugin.fileareas.forEach((filearea) => {
if (!filearea || !filearea.files) { if (!filearea || !filearea.files) {

View File

@ -17,7 +17,7 @@ import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
import { AddonModAssignDefaultFeedbackHandler } from './handlers/default-feedback'; import { AddonModAssignDefaultFeedbackHandler } from './handlers/default-feedback';
import { AddonModAssignAssign, AddonModAssignSubmission, AddonModAssignPlugin, AddonModAssignSavePluginData } from './assign'; import { AddonModAssignAssign, AddonModAssignSubmission, AddonModAssignPlugin, AddonModAssignSavePluginData } from './assign';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { AddonModAssignSubmissionFormatted } from './assign-helper'; import { AddonModAssignSubmissionFormatted } from './assign-helper';
import { CoreFormFields } from '@singletons/form'; import { CoreFormFields } from '@singletons/form';
@ -79,7 +79,7 @@ export interface AddonModAssignFeedbackHandler extends CoreDelegateHandler {
submission: AddonModAssignSubmission, submission: AddonModAssignSubmission,
plugin: AddonModAssignPlugin, plugin: AddonModAssignPlugin,
siteId?: string, siteId?: string,
): CoreWSExternalFile[] | Promise<CoreWSExternalFile[]>; ): CoreWSFile[] | Promise<CoreWSFile[]>;
/** /**
* Get a readable name to use for the plugin. * Get a readable name to use for the plugin.
@ -246,8 +246,8 @@ export class AddonModAssignFeedbackDelegateService extends CoreDelegate<AddonMod
submission: AddonModAssignSubmission, submission: AddonModAssignSubmission,
plugin: AddonModAssignPlugin, plugin: AddonModAssignPlugin,
siteId?: string, siteId?: string,
): Promise<CoreWSExternalFile[]> { ): Promise<CoreWSFile[]> {
const files: CoreWSExternalFile[] | undefined = const files: CoreWSFile[] | undefined =
await this.executeFunctionOnEnabled(plugin.type, 'getPluginFiles', [assign, submission, plugin, siteId]); await this.executeFunctionOnEnabled(plugin.type, 'getPluginFiles', [assign, submission, plugin, siteId]);
return files || []; return files || [];

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { Translate } from '@singletons'; import { Translate } from '@singletons';
import { AddonModAssignPlugin } from '../assign'; import { AddonModAssignPlugin } from '../assign';
import { AddonModAssignFeedbackHandler } from '../feedback-delegate'; import { AddonModAssignFeedbackHandler } from '../feedback-delegate';
@ -52,7 +52,7 @@ export class AddonModAssignDefaultFeedbackHandler implements AddonModAssignFeedb
* *
* @return The files (or promise resolved with the files). * @return The files (or promise resolved with the files).
*/ */
getPluginFiles(): CoreWSExternalFile[] { getPluginFiles(): CoreWSFile[] {
return []; return [];
} }

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { Translate } from '@singletons'; import { Translate } from '@singletons';
import { AddonModAssignPlugin } from '../assign'; import { AddonModAssignPlugin } from '../assign';
import { AddonModAssignSubmissionHandler } from '../submission-delegate'; import { AddonModAssignSubmissionHandler } from '../submission-delegate';
@ -79,7 +79,7 @@ export class AddonModAssignDefaultSubmissionHandler implements AddonModAssignSub
* *
* @return The files (or promise resolved with the files). * @return The files (or promise resolved with the files).
*/ */
getPluginFiles(): CoreWSExternalFile[] { getPluginFiles(): CoreWSFile[] {
return []; return [];
} }

View File

@ -26,7 +26,7 @@ import { AddonModAssignSubmissionDelegate } from '../submission-delegate';
import { AddonModAssignFeedbackDelegate } from '../feedback-delegate'; import { AddonModAssignFeedbackDelegate } from '../feedback-delegate';
import { CoreCourseActivityPrefetchHandlerBase } from '@features/course/classes/activity-prefetch-handler'; import { CoreCourseActivityPrefetchHandlerBase } from '@features/course/classes/activity-prefetch-handler';
import { CoreCourse, CoreCourseAnyModuleData, CoreCourseCommonModWSOptions } from '@features/course/services/course'; 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 { AddonModAssignHelper, AddonModAssignSubmissionFormatted } from '../assign-helper';
import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreCourseHelper } from '@features/course/services/course-helper';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
@ -82,13 +82,13 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref
* @param courseId Course ID the module belongs to. * @param courseId Course ID the module belongs to.
* @return Promise resolved with the list of files. * @return Promise resolved with the list of files.
*/ */
async getFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreWSExternalFile[]> { async getFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreWSFile[]> {
const siteId = CoreSites.getCurrentSiteId(); const siteId = CoreSites.getCurrentSiteId();
try { try {
const assign = await AddonModAssign.getAssignment(courseId, module.id, { siteId }); const assign = await AddonModAssign.getAssignment(courseId, module.id, { siteId });
// Get intro files and attachments. // Get intro files and attachments.
let files = assign.introattachments || []; let files: CoreWSFile[] = assign.introattachments || [];
files = files.concat(this.getIntroFilesFromInstance(module, assign)); files = files.concat(this.getIntroFilesFromInstance(module, assign));
// Now get the files in the submissions. // Now get the files in the submissions.
@ -145,7 +145,7 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref
submitId: number, submitId: number,
blindMarking: boolean, blindMarking: boolean,
siteId?: string, siteId?: string,
): Promise<CoreWSExternalFile[]> { ): Promise<CoreWSFile[]> {
const submissionStatus = await AddonModAssign.getSubmissionStatusWithRetry(assign, { const submissionStatus = await AddonModAssign.getSubmissionStatusWithRetry(assign, {
userId: submitId, userId: submitId,
@ -158,7 +158,7 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref
return []; return [];
} }
const promises: Promise<CoreWSExternalFile[]>[] = []; const promises: Promise<CoreWSFile[]>[] = [];
if (userSubmission.plugins) { if (userSubmission.plugins) {
// Add submission plugin files. // Add submission plugin files.
@ -245,7 +245,7 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref
// Get assignment to retrieve all its submissions. // Get assignment to retrieve all its submissions.
const assign = await AddonModAssign.getAssignment(courseId, module.id, options); const assign = await AddonModAssign.getAssignment(courseId, module.id, options);
const promises: Promise<any>[] = []; const promises: Promise<unknown>[] = [];
const blindMarking = assign.blindmarking && !assign.revealidentities; const blindMarking = assign.blindmarking && !assign.revealidentities;
if (blindMarking) { if (blindMarking) {
@ -259,7 +259,7 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref
promises.push(CoreCourseHelper.getModuleCourseIdByInstance(assign.id, 'assign', siteId)); promises.push(CoreCourseHelper.getModuleCourseIdByInstance(assign.id, 'assign', siteId));
// Download intro files and attachments. Do not call getFiles because it'd call some WS twice. // 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)); files = files.concat(this.getIntroFilesFromInstance(module, assign));
promises.push(CoreFilepool.addFilesToQueue(siteId, files, this.component, module.id)); promises.push(CoreFilepool.addFilesToQueue(siteId, files, this.component, module.id));
@ -293,7 +293,7 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref
// Get submissions. // Get submissions.
const submissions = await AddonModAssign.getSubmissions(assign.id, modOptions); const submissions = await AddonModAssign.getSubmissions(assign.id, modOptions);
const promises: Promise<any>[] = []; const promises: Promise<unknown>[] = [];
promises.push(this.prefetchParticipantSubmissions( promises.push(this.prefetchParticipantSubmissions(
assign, assign,
@ -359,7 +359,7 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref
AddonModAssignHelper.getSubmissionsUserData(assign, submissions, group.id, options) AddonModAssignHelper.getSubmissionsUserData(assign, submissions, group.id, options)
.then((submissions: AddonModAssignSubmissionFormatted[]) => { .then((submissions: AddonModAssignSubmissionFormatted[]) => {
const subPromises: Promise<any>[] = submissions.map((submission) => { const subPromises: Promise<unknown>[] = submissions.map((submission) => {
const submissionOptions = { const submissionOptions = {
userId: submission.submitid, userId: submission.submitid,
groupId: group.id, groupId: group.id,
@ -426,7 +426,7 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref
const userId = options.userId; const userId = options.userId;
try { try {
const promises: Promise<any>[] = []; const promises: Promise<unknown>[] = [];
const blindMarking = !!assign.blindmarking && !assign.revealidentities; const blindMarking = !!assign.blindmarking && !assign.revealidentities;
let userIds: number[] = []; let userIds: number[] = [];
const userSubmission = AddonModAssign.getSubmissionObjectFromAttempt(assign, submission.lastattempt); const userSubmission = AddonModAssign.getSubmissionObjectFromAttempt(assign, submission.lastattempt);

View File

@ -17,7 +17,7 @@ import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
import { AddonModAssignDefaultSubmissionHandler } from './handlers/default-submission'; import { AddonModAssignDefaultSubmissionHandler } from './handlers/default-submission';
import { AddonModAssignAssign, AddonModAssignSubmission, AddonModAssignPlugin, AddonModAssignSavePluginData } from './assign'; import { AddonModAssignAssign, AddonModAssignSubmission, AddonModAssignPlugin, AddonModAssignSavePluginData } from './assign';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { AddonModAssignSubmissionsDBRecordFormatted } from './assign-offline'; import { AddonModAssignSubmissionsDBRecordFormatted } from './assign-offline';
import { CoreFormFields } from '@singletons/form'; import { CoreFormFields } from '@singletons/form';
@ -139,7 +139,7 @@ export interface AddonModAssignSubmissionHandler extends CoreDelegateHandler {
submission: AddonModAssignSubmission, submission: AddonModAssignSubmission,
plugin: AddonModAssignPlugin, plugin: AddonModAssignPlugin,
siteId?: string, siteId?: string,
): CoreWSExternalFile[] | Promise<CoreWSExternalFile[]>; ): CoreWSFile[] | Promise<CoreWSFile[]>;
/** /**
* Get a readable name to use for the plugin. * Get a readable name to use for the plugin.
@ -384,8 +384,8 @@ export class AddonModAssignSubmissionDelegateService extends CoreDelegate<AddonM
submission: AddonModAssignSubmission, submission: AddonModAssignSubmission,
plugin: AddonModAssignPlugin, plugin: AddonModAssignPlugin,
siteId?: string, siteId?: string,
): Promise<CoreWSExternalFile[]> { ): Promise<CoreWSFile[]> {
const files: CoreWSExternalFile[] | undefined = const files: CoreWSFile[] | undefined =
await this.executeFunctionOnEnabled(plugin.type, 'getPluginFiles', [assign, submission, plugin, siteId]); await this.executeFunctionOnEnabled(plugin.type, 'getPluginFiles', [assign, submission, plugin, siteId]);
return files || []; return files || [];

View File

@ -24,10 +24,10 @@ import { AddonModAssignOffline, AddonModAssignSubmissionsDBRecordFormatted } fro
import { AddonModAssignSubmissionHandler } from '@addons/mod/assign/services/submission-delegate'; import { AddonModAssignSubmissionHandler } from '@addons/mod/assign/services/submission-delegate';
import { Injectable, Type } from '@angular/core'; import { Injectable, Type } from '@angular/core';
import { CoreFileUploader, CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader'; 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 { CoreFileSession } from '@services/file-session';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { AddonModAssignSubmissionFileComponent } from '../component/file'; import { AddonModAssignSubmissionFileComponent } from '../component/file';
import { FileEntry } from '@ionic-native/file/ngx'; import { FileEntry } from '@ionic-native/file/ngx';
@ -156,7 +156,7 @@ export class AddonModAssignSubmissionFileHandlerService implements AddonModAssig
assign: AddonModAssignAssign, assign: AddonModAssignAssign,
submission: AddonModAssignSubmission, submission: AddonModAssignSubmission,
plugin: AddonModAssignPlugin, plugin: AddonModAssignPlugin,
): CoreWSExternalFile[] { ): CoreWSFile[] {
return AddonModAssign.getSubmissionPluginAttachments(plugin); return AddonModAssign.getSubmissionPluginAttachments(plugin);
} }
@ -350,14 +350,14 @@ export class AddonModAssignSubmissionFileHandlerService implements AddonModAssig
submission: AddonModAssignSubmission, submission: AddonModAssignSubmission,
offlineData?: AddonModAssignSubmissionsDBRecordFormatted, offlineData?: AddonModAssignSubmissionsDBRecordFormatted,
siteId?: string, siteId?: string,
): Promise<(FileEntry | CoreWSExternalFile)[]> { ): Promise<CoreFileEntry[]> {
const filesData = <CoreFileUploaderStoreFilesResult>offlineData?.plugindata.files_filemanager; const filesData = <CoreFileUploaderStoreFilesResult>offlineData?.plugindata.files_filemanager;
if (!filesData) { if (!filesData) {
return []; return [];
} }
// Has some data to sync. // Has some data to sync.
let files: (FileEntry | CoreWSExternalFile)[] = filesData.online || []; let files: CoreFileEntry[] = filesData.online || [];
if (filesData.offline) { if (filesData.offline) {
// Has offline files, get them and add them to the list. // Has offline files, get them and add them to the list.

View File

@ -27,7 +27,7 @@ import { CoreFileHelper } from '@services/file-helper';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton, Translate } from '@singletons'; import { makeSingleton, Translate } from '@singletons';
import { AddonModAssignSubmissionOnlineTextComponent } from '../component/onlinetext'; import { AddonModAssignSubmissionOnlineTextComponent } from '../component/onlinetext';
@ -124,7 +124,7 @@ export class AddonModAssignSubmissionOnlineTextHandlerService implements AddonMo
assign: AddonModAssignAssign, assign: AddonModAssignAssign,
submission: AddonModAssignSubmission, submission: AddonModAssignSubmission,
plugin: AddonModAssignPlugin, plugin: AddonModAssignPlugin,
): CoreWSExternalFile[] { ): CoreWSFile[] {
return AddonModAssign.getSubmissionPluginAttachments(plugin); return AddonModAssign.getSubmissionPluginAttachments(plugin);
} }

View File

@ -16,7 +16,7 @@ import { Injectable } from '@angular/core';
import { CoreCourseResourcePrefetchHandlerBase } from '@features/course/classes/resource-prefetch-handler'; import { CoreCourseResourcePrefetchHandlerBase } from '@features/course/classes/resource-prefetch-handler';
import { CoreCourseAnyModuleData, CoreCourseWSModule } from '@features/course/services/course'; import { CoreCourseAnyModuleData, CoreCourseWSModule } from '@features/course/services/course';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { AddonModBook, AddonModBookProvider } from '../book'; import { AddonModBook, AddonModBookProvider } from '../book';
@ -55,7 +55,7 @@ export class AddonModBookPrefetchHandlerService extends CoreCourseResourcePrefet
* @param courseId Course ID. * @param courseId Course ID.
* @return Promise resolved with list of intro files. * @return Promise resolved with list of intro files.
*/ */
async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreWSExternalFile[]> { async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreWSFile[]> {
const book = await CoreUtils.ignoreErrors(AddonModBook.getBook(courseId, module.id)); const book = await CoreUtils.ignoreErrors(AddonModBook.getBook(courseId, module.id));
return this.getIntroFilesFromInstance(module, book); return this.getIntroFilesFromInstance(module, book);

View File

@ -19,7 +19,7 @@ import { CoreUser } from '@features/user/services/user';
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { AddonModChoice, AddonModChoiceProvider } from '../choice'; import { AddonModChoice, AddonModChoiceProvider } from '../choice';
import { AddonModChoiceSync, AddonModChoiceSyncResult } from '../choice-sync'; import { AddonModChoiceSync, AddonModChoiceSyncResult } from '../choice-sync';
@ -116,7 +116,7 @@ export class AddonModChoicePrefetchHandlerService extends CoreCourseActivityPref
/** /**
* @inheritdoc * @inheritdoc
*/ */
async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreWSExternalFile[]> { async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreWSFile[]> {
const choice = await CoreUtils.ignoreErrors(AddonModChoice.getChoice(courseId, module.id)); const choice = await CoreUtils.ignoreErrors(AddonModChoice.getChoice(courseId, module.id));
return this.getIntroFilesFromInstance(module, choice); return this.getIntroFilesFromInstance(module, choice);

View File

@ -15,8 +15,7 @@ import { Component } from '@angular/core';
import { AddonModDataEntryField, AddonModDataProvider } from '@addons/mod/data/services/data'; import { AddonModDataEntryField, AddonModDataProvider } from '@addons/mod/data/services/data';
import { AddonModDataFieldPluginComponent } from '@addons/mod/data/classes/field-plugin-component'; import { AddonModDataFieldPluginComponent } from '@addons/mod/data/classes/field-plugin-component';
import { CoreFileSession } from '@services/file-session'; import { CoreFileSession } from '@services/file-session';
import { CoreWSExternalFile } from '@services/ws'; import { CoreFileEntry } from '@services/file-helper';
import { FileEntry } from '@ionic-native/file';
/** /**
* Component to render data file field. * Component to render data file field.
@ -27,7 +26,7 @@ import { FileEntry } from '@ionic-native/file';
}) })
export class AddonModDataFieldFileComponent extends AddonModDataFieldPluginComponent { export class AddonModDataFieldFileComponent extends AddonModDataFieldPluginComponent {
files: (CoreWSExternalFile | FileEntry)[] = []; files: CoreFileEntry[] = [];
component?: string; component?: string;
componentId?: number; componentId?: number;
maxSizeBytes?: number; maxSizeBytes?: number;
@ -38,7 +37,7 @@ export class AddonModDataFieldFileComponent extends AddonModDataFieldPluginCompo
* @param value Input value. * @param value Input value.
* @return List of files. * @return List of files.
*/ */
protected getFiles(value?: Partial<AddonModDataEntryField>): (CoreWSExternalFile | FileEntry)[] { protected getFiles(value?: Partial<AddonModDataEntryField>): CoreFileEntry[] {
let files = value?.files || []; let files = value?.files || [];
// Reduce to first element. // Reduce to first element.

View File

@ -22,12 +22,12 @@ import {
import { AddonModDataFieldHandler } from '@addons/mod/data/services/data-fields-delegate'; import { AddonModDataFieldHandler } from '@addons/mod/data/services/data-fields-delegate';
import { Injectable, Type } from '@angular/core'; import { Injectable, Type } from '@angular/core';
import { CoreFileUploader, CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader'; 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 { CoreFileSession } from '@services/file-session';
import { CoreFormFields } from '@singletons/form'; import { CoreFormFields } from '@singletons/form';
import { CoreWSExternalFile } from '@services/ws';
import { makeSingleton, Translate } from '@singletons'; import { makeSingleton, Translate } from '@singletons';
import { AddonModDataFieldFileComponent } from '../component/file'; import { AddonModDataFieldFileComponent } from '../component/file';
import { CoreFileEntry } from '@services/file-helper';
/** /**
* Handler for file data field plugin. * Handler for file data field plugin.
@ -77,7 +77,7 @@ export class AddonModDataFieldFileHandlerService implements AddonModDataFieldHan
/** /**
* @inheritdoc * @inheritdoc
*/ */
getFieldEditFiles(field: AddonModDataField): (CoreWSExternalFile | FileEntry)[] { getFieldEditFiles(field: AddonModDataField): CoreFileEntry[] {
return CoreFileSession.getFiles(AddonModDataProvider.COMPONENT, field.dataid + '_' + field.id); return CoreFileSession.getFiles(AddonModDataProvider.COMPONENT, field.dataid + '_' + field.id);
} }

View File

@ -13,10 +13,9 @@
// limitations under the License. // limitations under the License.
import { AddonModDataEntryField, AddonModDataProvider } from '@addons/mod/data/services/data'; import { AddonModDataEntryField, AddonModDataProvider } from '@addons/mod/data/services/data';
import { Component } from '@angular/core'; 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 { CoreFileSession } from '@services/file-session';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreWSExternalFile } from '@services/ws';
import { AddonModDataFieldPluginComponent } from '../../../classes/field-plugin-component'; import { AddonModDataFieldPluginComponent } from '../../../classes/field-plugin-component';
/** /**
@ -28,12 +27,12 @@ import { AddonModDataFieldPluginComponent } from '../../../classes/field-plugin-
}) })
export class AddonModDataFieldPictureComponent extends AddonModDataFieldPluginComponent { export class AddonModDataFieldPictureComponent extends AddonModDataFieldPluginComponent {
files: (CoreWSExternalFile | FileEntry)[] = []; files: CoreFileEntry[] = [];
component?: string; component?: string;
componentId?: number; componentId?: number;
maxSizeBytes?: number; maxSizeBytes?: number;
image?: CoreWSExternalFile | FileEntry; image?: CoreFileEntry;
entryId?: number; entryId?: number;
imageUrl?: string; imageUrl?: string;
title?: string; title?: string;
@ -46,7 +45,7 @@ export class AddonModDataFieldPictureComponent extends AddonModDataFieldPluginCo
* @param value Input value. * @param value Input value.
* @return List of files. * @return List of files.
*/ */
protected getFiles(value?: Partial<AddonModDataEntryField>): (CoreWSExternalFile | FileEntry)[] { protected getFiles(value?: Partial<AddonModDataEntryField>): CoreFileEntry[] {
let files = value?.files || []; let files = value?.files || [];
// Reduce to first element. // Reduce to first element.
@ -65,9 +64,9 @@ export class AddonModDataFieldPictureComponent extends AddonModDataFieldPluginCo
* @return File found or false. * @return File found or false.
*/ */
protected findFile( protected findFile(
files: (CoreWSExternalFile | FileEntry)[], files: CoreFileEntry[],
filenameSeek: string, filenameSeek: string,
): CoreWSExternalFile | FileEntry | undefined { ): CoreFileEntry | undefined {
return files.find((file) => ('name' in file ? file.name : file.filename) == filenameSeek) || 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) { if (this.image) {
this.imageUrl = 'name' in this.image this.imageUrl = 'name' in this.image
? this.image.toURL() // Is Offline. ? this.image.toURL() // Is Offline.
: this.image.fileurl; : CoreFileHelper.getFileUrl(this.image);
} }
}, 1); }, 1);

View File

@ -22,12 +22,12 @@ import {
import { AddonModDataFieldHandler } from '@addons/mod/data/services/data-fields-delegate'; import { AddonModDataFieldHandler } from '@addons/mod/data/services/data-fields-delegate';
import { Injectable, Type } from '@angular/core'; import { Injectable, Type } from '@angular/core';
import { CoreFileUploader, CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader'; 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 { CoreFileSession } from '@services/file-session';
import { CoreFormFields } from '@singletons/form'; import { CoreFormFields } from '@singletons/form';
import { CoreWSExternalFile } from '@services/ws';
import { makeSingleton, Translate } from '@singletons'; import { makeSingleton, Translate } from '@singletons';
import { AddonModDataFieldPictureComponent } from '../component/picture'; import { AddonModDataFieldPictureComponent } from '../component/picture';
import { CoreFileEntry } from '@services/file-helper';
/** /**
* Handler for picture data field plugin. * Handler for picture data field plugin.
@ -88,7 +88,7 @@ export class AddonModDataFieldPictureHandlerService implements AddonModDataField
/** /**
* @inheritdoc * @inheritdoc
*/ */
getFieldEditFiles(field: AddonModDataField): (CoreWSExternalFile | FileEntry)[] { getFieldEditFiles(field: AddonModDataField): CoreFileEntry[] {
return CoreFileSession.getFiles(AddonModDataProvider.COMPONENT, field.dataid + '_' + field.id); return CoreFileSession.getFiles(AddonModDataProvider.COMPONENT, field.dataid + '_' + field.id);
} }

View File

@ -16,7 +16,7 @@ import { Component } from '@angular/core';
import { AddonModDataFieldPluginComponent } from '../../../classes/field-plugin-component'; import { AddonModDataFieldPluginComponent } from '../../../classes/field-plugin-component';
import { AddonModDataEntryField, AddonModDataProvider } from '@addons/mod/data/services/data'; import { AddonModDataEntryField, AddonModDataProvider } from '@addons/mod/data/services/data';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
/** /**
* Component to render data number field. * Component to render data number field.
@ -37,7 +37,7 @@ export class AddonModDataFieldTextareaComponent extends AddonModDataFieldPluginC
* @return Replaced string to be rendered. * @return Replaced string to be rendered.
*/ */
format(value?: Partial<AddonModDataEntryField>): string { format(value?: Partial<AddonModDataEntryField>): string {
const files: CoreWSExternalFile[] = (value && <CoreWSExternalFile[]>value.files) || []; const files: CoreWSFile[] = (value && <CoreWSFile[]>value.files) || [];
return value ? CoreTextUtils.replacePluginfileUrls(value.content || '', files) : ''; return value ? CoreTextUtils.replacePluginfileUrls(value.content || '', files) : '';
} }

View File

@ -14,13 +14,13 @@
import { AddonModDataEntryField, AddonModDataField, AddonModDataSubfieldData } from '@addons/mod/data/services/data'; import { AddonModDataEntryField, AddonModDataField, AddonModDataSubfieldData } from '@addons/mod/data/services/data';
import { Injectable, Type } from '@angular/core'; import { Injectable, Type } from '@angular/core';
import { FileEntry } from '@ionic-native/file';
import { CoreFormFields } from '@singletons/form'; import { CoreFormFields } from '@singletons/form';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton, Translate } from '@singletons'; import { makeSingleton, Translate } from '@singletons';
import { AddonModDataFieldTextHandlerService } from '../../text/services/handler'; import { AddonModDataFieldTextHandlerService } from '../../text/services/handler';
import { AddonModDataFieldTextareaComponent } from '../component/textarea'; import { AddonModDataFieldTextareaComponent } from '../component/textarea';
import { CoreFileEntry } from '@services/file-helper';
/** /**
* Handler for textarea data field plugin. * Handler for textarea data field plugin.
@ -49,7 +49,7 @@ export class AddonModDataFieldTextareaHandlerService extends AddonModDataFieldTe
const fieldName = 'f_' + field.id; const fieldName = 'f_' + field.id;
const files = this.getFieldEditFiles(field, inputData, originalFieldData); const files = this.getFieldEditFiles(field, inputData, originalFieldData);
let text = CoreTextUtils.restorePluginfileUrls(inputData[fieldName] || '', <CoreWSExternalFile[]>files); let text = CoreTextUtils.restorePluginfileUrls(inputData[fieldName] || '', <CoreWSFile[]> files);
// Add some HTML to the text if needed. // Add some HTML to the text if needed.
text = CoreTextUtils.formatHtmlLines(text); text = CoreTextUtils.formatHtmlLines(text);
@ -83,7 +83,7 @@ export class AddonModDataFieldTextareaHandlerService extends AddonModDataFieldTe
field: AddonModDataField, field: AddonModDataField,
inputData: CoreFormFields, inputData: CoreFormFields,
originalFieldData: AddonModDataEntryField, originalFieldData: AddonModDataEntryField,
): (CoreWSExternalFile | FileEntry)[] { ): CoreFileEntry[] {
return (originalFieldData && originalFieldData.files) || []; 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. // Take the original files since we cannot edit them on the app.
originalContent.content = CoreTextUtils.replacePluginfileUrls( originalContent.content = CoreTextUtils.replacePluginfileUrls(
originalContent.content, originalContent.content,
<CoreWSExternalFile[]>originalContent.files, <CoreWSFile[]> originalContent.files,
); );
} }

View File

@ -22,8 +22,8 @@ import { AddonModDataEntryField,
AddonModDataSubfieldData, AddonModDataSubfieldData,
} from './data'; } from './data';
import { CoreFormFields } from '@singletons/form'; import { CoreFormFields } from '@singletons/form';
import { CoreWSExternalFile } from '@services/ws'; import { FileEntry } from '@ionic-native/file/ngx';
import { FileEntry } from '@ionic-native/file'; import { CoreFileEntry } from '@services/file-helper';
/** /**
* Interface that all fields handlers must implement. * Interface that all fields handlers must implement.
@ -94,7 +94,7 @@ export interface AddonModDataFieldHandler extends CoreDelegateHandler {
field: AddonModDataField, field: AddonModDataField,
inputData: CoreFormFields, inputData: CoreFormFields,
originalFieldData: AddonModDataEntryField, originalFieldData: AddonModDataEntryField,
): (CoreWSExternalFile | FileEntry)[]; ): CoreFileEntry[];
/** /**
* Check and get field requeriments. * Check and get field requeriments.
@ -183,7 +183,7 @@ export class AddonModDataFieldsDelegateService extends CoreDelegate<AddonModData
field: AddonModDataField, field: AddonModDataField,
inputData: CoreFormFields, inputData: CoreFormFields,
originalFieldData: CoreFormFields, originalFieldData: CoreFormFields,
): (CoreWSExternalFile | FileEntry)[] { ): CoreFileEntry[] {
return this.executeFunctionOnEnabled(field.type, 'getFieldEditFiles', [field, inputData, originalFieldData]) || []; return this.executeFunctionOnEnabled(field.type, 'getFieldEditFiles', [field, inputData, originalFieldData]) || [];
} }

View File

@ -17,13 +17,12 @@ import { Injectable } from '@angular/core';
import { CoreCourse } from '@features/course/services/course'; import { CoreCourse } from '@features/course/services/course';
import { CoreFileUploader, CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader'; import { CoreFileUploader, CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader';
import { CoreRatingOffline } from '@features/rating/services/rating-offline'; import { CoreRatingOffline } from '@features/rating/services/rating-offline';
import { FileEntry } from '@ionic-native/file'; import { FileEntry } from '@ionic-native/file/ngx';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreFormFields } from '@singletons/form'; import { CoreFormFields } from '@singletons/form';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalFile } from '@services/ws';
import { makeSingleton, Translate } from '@singletons'; import { makeSingleton, Translate } from '@singletons';
import { CoreEvents } from '@singletons/events'; import { CoreEvents } from '@singletons/events';
import { import {
@ -44,6 +43,7 @@ import {
} from './data'; } from './data';
import { AddonModDataFieldsDelegate } from './data-fields-delegate'; import { AddonModDataFieldsDelegate } from './data-fields-delegate';
import { AddonModDataOffline, AddonModDataOfflineAction } from './data-offline'; import { AddonModDataOffline, AddonModDataOfflineAction } from './data-offline';
import { CoreFileEntry } from '@services/file-helper';
/** /**
* Service that provides helper functions for datas. * Service that provides helper functions for datas.
@ -605,7 +605,7 @@ export class AddonModDataHelperProvider {
inputData: CoreFormFields, inputData: CoreFormFields,
fields: AddonModDataField[], fields: AddonModDataField[],
entryContents: AddonModDataEntryFields, entryContents: AddonModDataEntryFields,
): Promise<(CoreWSExternalFile | FileEntry)[]> { ): Promise<CoreFileEntry[]> {
if (!inputData) { if (!inputData) {
return []; return [];
} }
@ -745,7 +745,7 @@ export class AddonModDataHelperProvider {
dataId: number, dataId: number,
entryId: number, entryId: number,
fieldId: number, fieldId: number,
files: (CoreWSExternalFile | FileEntry)[], files: CoreFileEntry[],
siteId?: string, siteId?: string,
): Promise<CoreFileUploaderStoreFilesResult> { ): Promise<CoreFileUploaderStoreFilesResult> {
// Get the folder where to store the files. // Get the folder where to store the files.
@ -771,7 +771,7 @@ export class AddonModDataHelperProvider {
itemId: number = 0, itemId: number = 0,
entryId: number, entryId: number,
fieldId: number, fieldId: number,
files: (CoreWSExternalFile | FileEntry)[], files: CoreFileEntry[],
offline: boolean, offline: boolean,
siteId?: string, siteId?: string,
): Promise<number | CoreFileUploaderStoreFilesResult> { ): Promise<number | CoreFileUploaderStoreFilesResult> {

View File

@ -21,13 +21,12 @@ import { CoreCourseCommonModWSOptions } from '@features/course/services/course';
import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreCourseLogHelper } from '@features/course/services/log-helper';
import { CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader'; import { CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader';
import { CoreRatingSync } from '@features/rating/services/rating-sync'; import { CoreRatingSync } from '@features/rating/services/rating-sync';
import { FileEntry } from '@ionic-native/file';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreFileEntry } from '@services/file-helper';
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
import { CoreSync } from '@services/sync'; import { CoreSync } from '@services/sync';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalFile } from '@services/ws';
import { Translate, makeSingleton } from '@singletons'; import { Translate, makeSingleton } from '@singletons';
import { CoreEvents } from '@singletons/events'; import { CoreEvents } from '@singletons/events';
import { AddonModDataProvider, AddonModData, AddonModDataData, AddonModDataAction } from './data'; import { AddonModDataProvider, AddonModData, AddonModDataData, AddonModDataAction } from './data';
@ -348,7 +347,7 @@ export class AddonModDataSyncProvider extends CoreCourseActivitySyncBaseProvider
// Upload Files if asked. // Upload Files if asked.
const value = CoreTextUtils.parseJSON<CoreFileUploaderStoreFilesResult>(field.value || ''); const value = CoreTextUtils.parseJSON<CoreFileUploaderStoreFilesResult>(field.value || '');
if (value.online || value.offline) { if (value.online || value.offline) {
let files: (CoreWSExternalFile | FileEntry)[] = value.online || []; let files: CoreFileEntry[] = value.online || [];
const offlineFiles = value.offline const offlineFiles = value.offline
? await AddonModDataHelper.getStoredFiles(editAction.dataid, entryId, field.fieldid) ? await AddonModDataHelper.getStoredFiles(editAction.dataid, entryId, field.fieldid)

View File

@ -19,8 +19,8 @@ import { CoreCourseCommonModWSOptions } from '@features/course/services/course';
import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreCourseLogHelper } from '@features/course/services/log-helper';
import { CoreRatingInfo } from '@features/rating/services/rating'; import { CoreRatingInfo } from '@features/rating/services/rating';
import { CoreTagItem } from '@features/tag/services/tag'; import { CoreTagItem } from '@features/tag/services/tag';
import { FileEntry } from '@ionic-native/file';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreFileEntry } from '@services/file-helper';
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
@ -1151,7 +1151,7 @@ export type AddonModDataEntryField = {
content2: string; // Contents. content2: string; // Contents.
content3: string; // Contents. content3: string; // Contents.
content4: string; // Contents. content4: string; // Contents.
files: (CoreWSExternalFile | FileEntry)[]; files: CoreFileEntry[];
}; };
/** /**
@ -1180,7 +1180,7 @@ export type AddonModDataSubfieldData = {
fieldid: number; fieldid: number;
subfield?: string; subfield?: string;
value?: unknown; // Value encoded in JSON. value?: unknown; // Value encoded in JSON.
files?: (CoreWSExternalFile | FileEntry)[]; files?: CoreFileEntry[];
}; };
/** /**

View File

@ -11,9 +11,9 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { FileEntry } from '@ionic-native/file'; import { CoreFileEntry } from '@services/file-helper';
import { CoreWSExternalFile } from '@services/ws';
import { AddonModDataEntryField, AddonModDataSearchEntriesAdvancedFieldFormatted, AddonModDataSubfieldData } from '../data'; import { AddonModDataEntryField, AddonModDataSearchEntriesAdvancedFieldFormatted, AddonModDataSubfieldData } from '../data';
import { AddonModDataFieldHandler } from '../data-fields-delegate'; import { AddonModDataFieldHandler } from '../data-fields-delegate';
@ -50,7 +50,7 @@ export class AddonModDataDefaultFieldHandler implements AddonModDataFieldHandler
/** /**
* @inheritdoc * @inheritdoc
*/ */
getFieldEditFiles(): (CoreWSExternalFile | FileEntry)[] { getFieldEditFiles(): CoreFileEntry[] {
return []; return [];
} }

View File

@ -21,7 +21,7 @@ import { CoreGroup, CoreGroups } from '@services/groups';
import { CoreSitesCommonWSOptions, CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSitesCommonWSOptions, CoreSites, CoreSitesReadingStrategy } from '@services/sites';
import { CoreTimeUtils } from '@services/utils/time'; import { CoreTimeUtils } from '@services/utils/time';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { AddonModDataProvider, AddonModDataEntry, AddonModData, AddonModDataData } from '../data'; import { AddonModDataProvider, AddonModDataEntry, AddonModData, AddonModDataData } from '../data';
import { AddonModDataSync, AddonModDataSyncResult } from '../data-sync'; import { AddonModDataSync, AddonModDataSyncResult } from '../data-sync';
@ -82,10 +82,10 @@ export class AddonModDataPrefetchHandlerService extends CoreCourseActivityPrefet
courseId: number, courseId: number,
omitFail: boolean, omitFail: boolean,
options: CoreCourseCommonModWSOptions = {}, options: CoreCourseCommonModWSOptions = {},
): Promise<{ database: AddonModDataData; groups: CoreGroup[]; entries: AddonModDataEntry[]; files: CoreWSExternalFile[]}> { ): Promise<{ database: AddonModDataData; groups: CoreGroup[]; entries: AddonModDataEntry[]; files: CoreWSFile[]}> {
let groups: CoreGroup[] = []; let groups: CoreGroup[] = [];
let entries: AddonModDataEntry[] = []; let entries: AddonModDataEntry[] = [];
let files: CoreWSExternalFile[] = []; let files: CoreWSFile[] = [];
options.cmId = options.cmId || module.id; options.cmId = options.cmId || module.id;
options.siteId = options.siteId || CoreSites.getCurrentSiteId(); options.siteId = options.siteId || CoreSites.getCurrentSiteId();
@ -131,12 +131,12 @@ export class AddonModDataPrefetchHandlerService extends CoreCourseActivityPrefet
* @param entries List of entries to get files from. * @param entries List of entries to get files from.
* @return List of files. * @return List of files.
*/ */
protected getEntriesFiles(entries: AddonModDataEntry[]): CoreWSExternalFile[] { protected getEntriesFiles(entries: AddonModDataEntry[]): CoreWSFile[] {
let files: CoreWSExternalFile[] = []; let files: CoreWSFile[] = [];
entries.forEach((entry) => { entries.forEach((entry) => {
CoreUtils.objectToArray(entry.contents).forEach((content) => { CoreUtils.objectToArray(entry.contents).forEach((content) => {
files = files.concat(<CoreWSExternalFile[]>content.files); files = files.concat(<CoreWSFile[]>content.files);
}); });
}); });
@ -146,14 +146,14 @@ export class AddonModDataPrefetchHandlerService extends CoreCourseActivityPrefet
/** /**
* @inheritdoc * @inheritdoc
*/ */
async getFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreWSExternalFile[]> { async getFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreWSFile[]> {
return this.getDatabaseInfoHelper(module, courseId, true).then((info) => info.files); return this.getDatabaseInfoHelper(module, courseId, true).then((info) => info.files);
} }
/** /**
* @inheritdoc * @inheritdoc
*/ */
async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreWSExternalFile[]> { async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreWSFile[]> {
const data = await CoreUtils.ignoreErrors(AddonModData.getDatabase(courseId, module.id)); const data = await CoreUtils.ignoreErrors(AddonModData.getDatabase(courseId, module.id));
return this.getIntroFilesFromInstance(module, data); return this.getIntroFilesFromInstance(module, data);

View File

@ -14,13 +14,14 @@
import { Component, ViewChild, ElementRef, Input, OnInit } from '@angular/core'; import { Component, ViewChild, ElementRef, Input, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms'; 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 { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { ModalController, Translate } from '@singletons'; import { ModalController, Translate } from '@singletons';
import { AddonModForumData, AddonModForumPost, AddonModForumReply } from '@addons/mod/forum/services/forum'; import { AddonModForumData, AddonModForumPost, AddonModForumReply } from '@addons/mod/forum/services/forum';
import { AddonModForumHelper } from '@addons/mod/forum/services/forum-helper'; import { AddonModForumHelper } from '@addons/mod/forum/services/forum-helper';
import { CoreForms } from '@singletons/form'; import { CoreForms } from '@singletons/form';
import { CoreFileEntry } from '@services/file-helper';
/** /**
* Page that displays a form to edit discussion post. * Page that displays a form to edit discussion post.

View File

@ -38,11 +38,10 @@ import {
AddonModForumProvider, AddonModForumProvider,
AddonModForumReply, AddonModForumReply,
AddonModForumUpdateDiscussionPostWSOptionsObject, AddonModForumUpdateDiscussionPostWSOptionsObject,
AddonModForumWSPostAttachment,
} from '../../services/forum'; } from '../../services/forum';
import { CoreTag } from '@features/tag/services/tag'; import { CoreTag } from '@features/tag/services/tag';
import { ModalController, PopoverController, Translate } from '@singletons'; 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 { IonContent } from '@ionic/angular';
import { AddonModForumSync } from '../../services/forum-sync'; import { AddonModForumSync } from '../../services/forum-sync';
import { CoreSync } from '@services/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 { AddonModForumEditPostComponent } from '../edit-post/edit-post';
import { CoreRatingInfo } from '@features/rating/services/rating'; import { CoreRatingInfo } from '@features/rating/services/rating';
import { CoreForms } from '@singletons/form'; 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.). * 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, isEditing?: boolean,
subject?: string, subject?: string,
message?: string, message?: string,
files?: (CoreFileEntry | AddonModForumWSPostAttachment)[], files?: CoreFileEntry[],
isPrivate?: boolean, isPrivate?: boolean,
): void { ): void {
// Delete the local files from the tmp folder if any. // Delete the local files from the tmp folder if any.

View File

@ -14,7 +14,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { FileEntry } from '@ionic-native/file/ngx'; 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 { CoreUser } from '@features/user/services/user';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreFile } from '@services/file'; import { CoreFile } from '@services/file';
@ -31,6 +31,7 @@ import {
AddonModForumProvider, AddonModForumProvider,
} from './forum'; } from './forum';
import { AddonModForumDiscussionOptions, AddonModForumOffline, AddonModForumOfflineReply } from './forum-offline'; import { AddonModForumDiscussionOptions, AddonModForumOffline, AddonModForumOfflineReply } from './forum-offline';
import { CoreFileEntry } from '@services/file-helper';
/** /**
* Service that provides some features for forums. * Service that provides some features for forums.

View File

@ -16,17 +16,17 @@ import { Injectable } from '@angular/core';
import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; import { CoreSite, CoreSiteWSPreSets } from '@classes/site';
import { CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { CoreCourseCommonModWSOptions } from '@features/course/services/course';
import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreCourseLogHelper } from '@features/course/services/log-helper';
import { CoreFileEntry } from '@features/fileuploader/services/fileuploader';
import { CoreRatingInfo } from '@features/rating/services/rating'; import { CoreRatingInfo } from '@features/rating/services/rating';
import { CoreTagItem } from '@features/tag/services/tag'; import { CoreTagItem } from '@features/tag/services/tag';
import { CoreUser } from '@features/user/services/user'; import { CoreUser } from '@features/user/services/user';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreFileEntry } from '@services/file-helper';
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
import { CoreGroups } from '@services/groups'; import { CoreGroups } from '@services/groups';
import { CoreSitesCommonWSOptions, CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSitesCommonWSOptions, CoreSites, CoreSitesReadingStrategy } from '@services/sites';
import { CoreUrlUtils } from '@services/utils/url'; import { CoreUrlUtils } from '@services/utils/url';
import { CoreUtils } from '@services/utils/utils'; 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 { makeSingleton, Translate } from '@singletons';
import { AddonModForumOffline, AddonModForumOfflineDiscussion, AddonModForumReplyOptions } from './forum-offline'; import { AddonModForumOffline, AddonModForumOfflineDiscussion, AddonModForumReplyOptions } from './forum-offline';
@ -1469,7 +1469,7 @@ export type AddonModForumPost = {
canreplyprivately?: boolean; // Whether the user can post a private reply. canreplyprivately?: boolean; // Whether the user can post a private reply.
}; };
attachment?: 0 | 1; attachment?: 0 | 1;
attachments?: (CoreFileEntry | AddonModForumWSPostAttachment)[]; attachments?: CoreFileEntry[];
messageinlinefiles?: CoreWSExternalFile[]; messageinlinefiles?: CoreWSExternalFile[];
haswordcount?: boolean; // Haswordcount. haswordcount?: boolean; // Haswordcount.
wordcount?: number; // Wordcount. wordcount?: number; // Wordcount.
@ -1580,7 +1580,7 @@ export type AddonModForumReply = {
id: number; id: number;
subject: string; subject: string;
message: string; message: string;
files: (CoreFileEntry | AddonModForumWSPostAttachment)[]; files: CoreFileEntry[];
}; };
/** /**
@ -1600,37 +1600,6 @@ export type AddonModForumSortOrder = {
value: number; 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. * 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. markasunread?: string; // The URL used to mark the post as unread.
discuss?: string; // Discuss. discuss?: string; // Discuss.
}; };
attachments: AddonModForumWSPostAttachment[]; // Attachments. attachments: CoreWSStoredFile[]; // Attachments.
tags?: { // Tags. tags?: { // Tags.
id: number; // The ID of the Tag. id: number; // The ID of the Tag.
tagid: number; // The tagid. tagid: number; // The tagid.

View File

@ -17,7 +17,7 @@ import { CoreCourseActivityPrefetchHandlerBase } from '@features/course/classes/
import { AddonModForum, AddonModForumData, AddonModForumPost, AddonModForumProvider } from '../forum'; import { AddonModForum, AddonModForumData, AddonModForumPost, AddonModForumProvider } from '../forum';
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
import { CoreFilepool } from '@services/filepool'; 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 { CoreCourse, CoreCourseAnyModuleData, CoreCourseCommonModWSOptions } from '@features/course/services/course';
import { CoreUser } from '@features/user/services/user'; import { CoreUser } from '@features/user/services/user';
import { CoreGroups, CoreGroupsProvider } from '@services/groups'; 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. * @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. * @return Promise resolved with the list of files.
*/ */
async getFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreWSExternalFile[]> { async getFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreWSFile[]> {
try { try {
const forum = await AddonModForum.getForum(courseId, module.id); const forum = await AddonModForum.getForum(courseId, module.id);
@ -69,13 +69,13 @@ export class AddonModForumPrefetchHandlerService extends CoreCourseActivityPrefe
* @param posts Forum posts. * @param posts Forum posts.
* @return Files. * @return Files.
*/ */
protected getPostsFiles(posts: AddonModForumPost[]): CoreWSExternalFile[] { protected getPostsFiles(posts: AddonModForumPost[]): CoreWSFile[] {
let files: CoreWSExternalFile[] = []; let files: CoreWSFile[] = [];
const getInlineFiles = CoreSites.getCurrentSite()?.isVersionGreaterEqualThan('3.2'); const getInlineFiles = CoreSites.getCurrentSite()?.isVersionGreaterEqualThan('3.2');
posts.forEach((post) => { posts.forEach((post) => {
if (post.attachments && post.attachments.length) { 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) { if (getInlineFiles && post.messageinlinefiles && post.messageinlinefiles.length) {
files = files.concat(post.messageinlinefiles); files = files.concat(post.messageinlinefiles);

View File

@ -20,7 +20,7 @@ import { CoreUtils } from '@services/utils/utils';
import { AddonModGlossaryOffline } from './glossary-offline'; import { AddonModGlossaryOffline } from './glossary-offline';
import { AddonModGlossaryNewEntry, AddonModGlossaryNewEntryWithFiles } from './glossary'; import { AddonModGlossaryNewEntry, AddonModGlossaryNewEntryWithFiles } from './glossary';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { CoreWSExternalFile } from '@services/ws'; import { CoreFileEntry } from '@services/file-helper';
/** /**
* Helper to gather some common functions for glossary. * Helper to gather some common functions for glossary.
@ -68,7 +68,7 @@ export class AddonModGlossaryHelperProvider {
*/ */
hasEntryDataChanged( hasEntryDataChanged(
entry: AddonModGlossaryNewEntry, entry: AddonModGlossaryNewEntry,
files: (CoreWSExternalFile | FileEntry)[], files: CoreFileEntry[],
original?: AddonModGlossaryNewEntryWithFiles, original?: AddonModGlossaryNewEntryWithFiles,
): boolean { ): boolean {
if (!original || typeof original.concept == 'undefined') { if (!original || typeof original.concept == 'undefined') {
@ -98,7 +98,7 @@ export class AddonModGlossaryHelperProvider {
glossaryId: number, glossaryId: number,
entryName: string, entryName: string,
timeCreated: number, timeCreated: number,
files: (CoreWSExternalFile | FileEntry)[], files: CoreFileEntry[],
siteId?: string, siteId?: string,
): Promise<CoreFileUploaderStoreFilesResult> { ): Promise<CoreFileUploaderStoreFilesResult> {
// Get the folder where to store the files. // Get the folder where to store the files.

View File

@ -14,7 +14,6 @@
import { ContextLevel } from '@/core/constants'; import { ContextLevel } from '@/core/constants';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { FileEntry } from '@ionic-native/file/ngx';
import { CoreSyncBlockedError } from '@classes/base-sync'; import { CoreSyncBlockedError } from '@classes/base-sync';
import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreNetworkError } from '@classes/errors/network-error';
import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/activity-sync'; import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/activity-sync';
@ -24,13 +23,13 @@ import { CoreApp } from '@services/app';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreSync } from '@services/sync'; import { CoreSync } from '@services/sync';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalFile } from '@services/ws';
import { makeSingleton, Translate } from '@singletons'; import { makeSingleton, Translate } from '@singletons';
import { CoreEvents } from '@singletons/events'; import { CoreEvents } from '@singletons/events';
import { AddonModGlossary, AddonModGlossaryProvider } from './glossary'; import { AddonModGlossary, AddonModGlossaryProvider } from './glossary';
import { AddonModGlossaryHelper } from './glossary-helper'; import { AddonModGlossaryHelper } from './glossary-helper';
import { AddonModGlossaryOffline, AddonModGlossaryOfflineEntry } from './glossary-offline'; import { AddonModGlossaryOffline, AddonModGlossaryOfflineEntry } from './glossary-offline';
import { CoreFileUploader } from '@features/fileuploader/services/fileuploader'; import { CoreFileUploader } from '@features/fileuploader/services/fileuploader';
import { CoreFileEntry } from '@services/file-helper';
/** /**
* Service to sync glossaries. * Service to sync glossaries.
@ -309,7 +308,7 @@ export class AddonModGlossarySyncProvider extends CoreCourseActivitySyncBaseProv
} }
// Has some attachments to sync. // Has some attachments to sync.
let files: (CoreWSExternalFile | FileEntry)[] = entry.attachments.online || []; let files: CoreFileEntry[] = entry.attachments.online || [];
if (entry.attachments.offline) { if (entry.attachments.offline) {
// Has offline files. // Has offline files.

View File

@ -13,7 +13,6 @@
// limitations under the License. // limitations under the License.
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { FileEntry } from '@ionic-native/file/ngx';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; import { CoreSite, CoreSiteWSPreSets } from '@classes/site';
import { CoreCourseCommonModWSOptions } from '@features/course/services/course'; 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 { AddonModGlossaryEntryDBRecord, ENTRIES_TABLE_NAME } from './database/glossary';
import { AddonModGlossaryOffline } from './glossary-offline'; import { AddonModGlossaryOffline } from './glossary-offline';
import { AddonModGlossaryAutoSyncData, AddonModGlossarySyncProvider } from './glossary-sync'; import { AddonModGlossaryAutoSyncData, AddonModGlossarySyncProvider } from './glossary-sync';
import { CoreFileEntry } from '@services/file-helper';
const ROOT_CACHE_KEY = 'mmaModGlossary:'; const ROOT_CACHE_KEY = 'mmaModGlossary:';
@ -1431,7 +1431,7 @@ export type AddonModGlossaryNewEntry = {
* Entry to be added, including attachments. * Entry to be added, including attachments.
*/ */
export type AddonModGlossaryNewEntryWithFiles = AddonModGlossaryNewEntry & { export type AddonModGlossaryNewEntryWithFiles = AddonModGlossaryNewEntry & {
files: (CoreWSExternalFile | FileEntry)[]; files: CoreFileEntry[];
}; };
/** /**

View File

@ -19,7 +19,7 @@ import { CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/c
import { CoreUser } from '@features/user/services/user'; import { CoreUser } from '@features/user/services/user';
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { AddonModGlossary, AddonModGlossaryEntry, AddonModGlossaryGlossary, AddonModGlossaryProvider } from '../glossary'; import { AddonModGlossary, AddonModGlossaryEntry, AddonModGlossaryGlossary, AddonModGlossaryProvider } from '../glossary';
import { AddonModGlossarySync, AddonModGlossarySyncResult } from '../glossary-sync'; import { AddonModGlossarySync, AddonModGlossarySyncResult } from '../glossary-sync';
@ -38,7 +38,7 @@ export class AddonModGlossaryPrefetchHandlerService extends CoreCourseActivityPr
/** /**
* @inheritdoc * @inheritdoc
*/ */
async getFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreWSExternalFile[]> { async getFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreWSFile[]> {
try { try {
const glossary = await AddonModGlossary.getGlossary(courseId, module.id); const glossary = await AddonModGlossary.getGlossary(courseId, module.id);
@ -68,7 +68,7 @@ export class AddonModGlossaryPrefetchHandlerService extends CoreCourseActivityPr
module: CoreCourseAnyModuleData, module: CoreCourseAnyModuleData,
glossary: AddonModGlossaryGlossary, glossary: AddonModGlossaryGlossary,
entries: AddonModGlossaryEntry[], entries: AddonModGlossaryEntry[],
): CoreWSExternalFile[] { ): CoreWSFile[] {
let files = this.getIntroFilesFromInstance(module, glossary); let files = this.getIntroFilesFromInstance(module, glossary);
const getInlineFiles = CoreSites.getCurrentSite()?.isVersionGreaterEqualThan('3.2'); const getInlineFiles = CoreSites.getCurrentSite()?.isVersionGreaterEqualThan('3.2');

View File

@ -30,7 +30,7 @@ import { CoreFilepool } from '@services/filepool';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreEventObserver, CoreEvents } from '@singletons/events';
import { import {
AddonModH5PActivity, AddonModH5PActivity,
@ -43,6 +43,7 @@ import {
AddonModH5PActivitySyncProvider, AddonModH5PActivitySyncProvider,
AddonModH5PActivitySyncResult, AddonModH5PActivitySyncResult,
} from '../../services/h5pactivity-sync'; } from '../../services/h5pactivity-sync';
import { CoreFileHelper } from '@services/file-helper';
/** /**
* Component that displays an H5P activity entry page. * Component that displays an H5P activity entry page.
@ -58,7 +59,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
h5pActivity?: AddonModH5PActivityData; // The H5P activity object. h5pActivity?: AddonModH5PActivityData; // The H5P activity object.
accessInfo?: AddonModH5PActivityAccessInfo; // Info about the user capabilities. 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. stateMessage?: string; // Message about the file state.
downloading = false; // Whether the H5P file is being downloaded. downloading = false; // Whether the H5P file is being downloaded.
@ -191,10 +192,10 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
siteId: this.siteId, siteId: this.siteId,
}); });
this.fileUrl = this.deployedFile.fileurl; this.fileUrl = CoreFileHelper.getFileUrl(this.deployedFile);
// Listen for changes in the state. // 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) { if (!this.observer) {
this.observer = CoreEvents.on(eventName, () => { this.observer = CoreEvents.on(eventName, () => {
@ -213,7 +214,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
protected async calculateFileState(): Promise<void> { protected async calculateFileState(): Promise<void> {
this.state = await CoreFilepool.getFileStateByUrl( this.state = await CoreFilepool.getFileStateByUrl(
this.site.getId(), this.site.getId(),
this.deployedFile!.fileurl, this.fileUrl!,
this.deployedFile!.timemodified, this.deployedFile!.timemodified,
); );
@ -317,7 +318,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
try { try {
await CoreFilepool.downloadUrl( await CoreFilepool.downloadUrl(
this.site.getId(), this.site.getId(),
this.deployedFile!.fileurl, this.fileUrl!,
false, false,
this.component, this.component,
this.componentId, this.componentId,

View File

@ -15,7 +15,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites'; 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 { CoreTimeUtils } from '@services/utils/time';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; import { CoreSite, CoreSiteWSPreSets } from '@classes/site';
@ -305,7 +305,7 @@ export class AddonModH5PActivityProvider {
async getDeployedFile( async getDeployedFile(
h5pActivity: AddonModH5PActivityData, h5pActivity: AddonModH5PActivityData,
options?: AddonModH5PActivityGetDeployedFileOptions, options?: AddonModH5PActivityGetDeployedFileOptions,
): Promise<CoreWSExternalFile> { ): Promise<CoreWSFile> {
if (h5pActivity.deployedfile) { if (h5pActivity.deployedfile) {
// File already deployed and still valid, use this one. // File already deployed and still valid, use this one.

View File

@ -21,7 +21,7 @@ import { CoreH5P } from '@features/h5p/services/h5p';
import { CoreUser } from '@features/user/services/user'; import { CoreUser } from '@features/user/services/user';
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { AddonModH5PActivity, AddonModH5PActivityData, AddonModH5PActivityProvider } from '../h5pactivity'; import { AddonModH5PActivity, AddonModH5PActivityData, AddonModH5PActivityProvider } from '../h5pactivity';
@ -39,7 +39,7 @@ export class AddonModH5PActivityPrefetchHandlerService extends CoreCourseActivit
/** /**
* @inheritdoc * @inheritdoc
*/ */
async getFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreWSExternalFile[]> { async getFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreWSFile[]> {
const h5pActivity = await AddonModH5PActivity.getH5PActivity(courseId, module.id); const h5pActivity = await AddonModH5PActivity.getH5PActivity(courseId, module.id);

View File

@ -23,7 +23,7 @@ import {
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { AddonModImscp, AddonModImscpProvider } from '../imscp'; import { AddonModImscp, AddonModImscpProvider } from '../imscp';
@ -58,7 +58,7 @@ export class AddonModImscpPrefetchHandlerService extends CoreCourseResourcePrefe
/** /**
* @inheritdoc * @inheritdoc
*/ */
async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreWSExternalFile[]> { async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreWSFile[]> {
// If not found, use undefined so module description is used. // If not found, use undefined so module description is used.
const imscp = await CoreUtils.ignoreErrors(AddonModImscp.getImscp(courseId, module.id)); const imscp = await CoreUtils.ignoreErrors(AddonModImscp.getImscp(courseId, module.id));

View File

@ -17,7 +17,7 @@ import { CoreCourseResourcePrefetchHandlerBase } from '@features/course/classes/
import { CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/course'; import { CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/course';
import { CoreSitesReadingStrategy } from '@services/sites'; import { CoreSitesReadingStrategy } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { AddonModLabel, AddonModLabelLabel, AddonModLabelProvider } from '../label'; import { AddonModLabel, AddonModLabelLabel, AddonModLabelProvider } from '../label';
@ -36,7 +36,7 @@ export class AddonModLabelPrefetchHandlerService extends CoreCourseResourcePrefe
/** /**
* @inheritdoc * @inheritdoc
*/ */
async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number, ignoreCache?: boolean): Promise<CoreWSExternalFile[]> { async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number, ignoreCache?: boolean): Promise<CoreWSFile[]> {
let label: AddonModLabelLabel | undefined; let label: AddonModLabelLabel | undefined;
if (AddonModLabel.isGetLabelAvailableForSite()) { if (AddonModLabel.isGetLabelAvailableForSite()) {

View File

@ -23,7 +23,7 @@ import { CoreGroups } from '@services/groups';
import { CoreFileSizeSum, CorePluginFileDelegate } from '@services/plugin-file-delegate'; import { CoreFileSizeSum, CorePluginFileDelegate } from '@services/plugin-file-delegate';
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton, ModalController, Translate } from '@singletons'; import { makeSingleton, ModalController, Translate } from '@singletons';
import { AddonModLessonPasswordModalComponent } from '../../components/password-modal/password-modal'; import { AddonModLessonPasswordModalComponent } from '../../components/password-modal/password-modal';
import { import {
@ -92,7 +92,7 @@ export class AddonModLessonPrefetchHandlerService extends CoreCourseActivityPref
lesson = passwordData.lesson || lesson; lesson = passwordData.lesson || lesson;
// Get intro files and media files. // Get intro files and media files.
let files = lesson.mediafiles || []; let files: CoreWSFile[] = lesson.mediafiles || [];
files = files.concat(this.getIntroFilesFromInstance(module, lesson)); files = files.concat(this.getIntroFilesFromInstance(module, lesson));
const result = await CorePluginFileDelegate.getFilesDownloadSize(files); const result = await CorePluginFileDelegate.getFilesDownloadSize(files);
@ -289,7 +289,8 @@ export class AddonModLessonPrefetchHandlerService extends CoreCourseActivityPref
const promises: Promise<void>[] = []; const promises: Promise<void>[] = [];
// Download intro files and media files. // 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)); promises.push(CoreFilepool.addFilesToQueue(siteId, files, this.component, module.id));
if (AddonModLesson.isLessonOffline(lesson)) { if (AddonModLesson.isLessonOffline(lesson)) {
@ -495,7 +496,7 @@ export class AddonModLessonPrefetchHandlerService extends CoreCourseActivityPref
} }
// Download embedded files in essays. // Download embedded files in essays.
const files: CoreWSExternalFile[] = []; const files: CoreWSFile[] = [];
attempt.answerpages.forEach((answerPage) => { attempt.answerpages.forEach((answerPage) => {
if (!answerPage.page || answerPage.page.qtype != AddonModLessonProvider.LESSON_PAGE_ESSAY) { if (!answerPage.page || answerPage.page.qtype != AddonModLessonProvider.LESSON_PAGE_ESSAY) {
return; return;

View File

@ -23,7 +23,7 @@ import { CoreFilepool } from '@services/filepool';
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { AddonModQuizAccessRuleDelegate } from '../access-rules-delegate'; import { AddonModQuizAccessRuleDelegate } from '../access-rules-delegate';
import { import {
@ -77,7 +77,7 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet
* @return Promise resolved with the list of files. * @return Promise resolved with the list of files.
*/ */
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
async getFiles(module: CoreCourseAnyModuleData, courseId: number, single?: boolean): Promise<CoreWSExternalFile[]> { async getFiles(module: CoreCourseAnyModuleData, courseId: number, single?: boolean): Promise<CoreWSFile[]> {
try { try {
const quiz = await AddonModQuiz.getQuiz(courseId, module.id); const quiz = await AddonModQuiz.getQuiz(courseId, module.id);
@ -109,9 +109,9 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet
quiz: AddonModQuizQuizWSData, quiz: AddonModQuizQuizWSData,
attempts: AddonModQuizAttemptWSData[], attempts: AddonModQuizAttemptWSData[],
siteId?: string, siteId?: string,
): Promise<CoreWSExternalFile[]> { ): Promise<CoreWSFile[]> {
const getInlineFiles = CoreSites.getCurrentSite()?.isVersionGreaterEqualThan('3.2'); const getInlineFiles = CoreSites.getCurrentSite()?.isVersionGreaterEqualThan('3.2');
let files: CoreWSExternalFile[] = []; let files: CoreWSFile[] = [];
await Promise.all(attempts.map(async (attempt) => { await Promise.all(attempts.map(async (attempt) => {
if (!AddonModQuiz.isAttemptFinished(attempt.state)) { if (!AddonModQuiz.isAttemptFinished(attempt.state)) {

View File

@ -22,7 +22,7 @@ import { CoreNavigationOptions, CoreNavigator } from '@services/navigator';
import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreMimetypeUtils } from '@services/utils/mimetype';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreTimeUtils } from '@services/utils/time'; import { CoreTimeUtils } from '@services/utils/time';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton, Translate } from '@singletons'; import { makeSingleton, Translate } from '@singletons';
import { AddonModResourceIndexComponent } from '../../components/index'; import { AddonModResourceIndexComponent } from '../../components/index';
import { AddonModResource, AddonModResourceCustomData } from '../resource'; import { AddonModResource, AddonModResourceCustomData } from '../resource';
@ -142,7 +142,7 @@ export class AddonModResourceModuleHandlerService implements CoreCourseModuleHan
handlerData: CoreCourseModuleHandlerData, handlerData: CoreCourseModuleHandlerData,
): Promise<AddonResourceHandlerData> { ): Promise<AddonResourceHandlerData> {
const promises: Promise<void>[] = []; const promises: Promise<void>[] = [];
let infoFiles: CoreWSExternalFile[] = []; let infoFiles: CoreWSFile[] = [];
let options: AddonModResourceCustomData = {}; let options: AddonModResourceCustomData = {};
// Check if the button needs to be shown or not. // Check if the button needs to be shown or not.
@ -166,7 +166,7 @@ export class AddonModResourceModuleHandlerService implements CoreCourseModuleHan
await Promise.all(promises); await Promise.all(promises);
const files: (CoreCourseModuleContentFile | CoreWSExternalFile)[] = module.contents && module.contents.length const files: (CoreCourseModuleContentFile | CoreWSFile)[] = module.contents && module.contents.length
? module.contents ? module.contents
: infoFiles; : infoFiles;

View File

@ -22,7 +22,7 @@ import { CoreFilepool } from '@services/filepool';
import { CoreFileSizeSum } from '@services/plugin-file-delegate'; import { CoreFileSizeSum } from '@services/plugin-file-delegate';
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton, Translate } from '@singletons'; import { makeSingleton, Translate } from '@singletons';
import { AddonModScorm, AddonModScormProvider, AddonModScormScorm } from '../scorm'; import { AddonModScorm, AddonModScormProvider, AddonModScormScorm } from '../scorm';
import { AddonModScormSync } from '../scorm-sync'; 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. * @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. * @return Promise resolved with the list of files.
*/ */
async getFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreWSExternalFile[]> { async getFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreWSFile[]> {
try { try {
const scorm = await this.getScorm(module, courseId); const scorm = await this.getScorm(module, courseId);

View File

@ -25,7 +25,7 @@ import { CoreTextUtils } from '@services/utils/text';
import { CoreTimeUtils } from '@services/utils/time'; import { CoreTimeUtils } from '@services/utils/time';
import { CoreUrlUtils } from '@services/utils/url'; import { CoreUrlUtils } from '@services/utils/url';
import { CoreUtils } from '@services/utils/utils'; 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 { makeSingleton, Translate } from '@singletons';
import { CoreEvents } from '@singletons/events'; import { CoreEvents } from '@singletons/events';
import { AddonModScormOffline } from './scorm-offline'; import { AddonModScormOffline } from './scorm-offline';
@ -983,8 +983,8 @@ export class AddonModScormProvider {
* @param scorm SCORM. * @param scorm SCORM.
* @return File list. * @return File list.
*/ */
getScormFileList(scorm: AddonModScormScorm): CoreWSExternalFile[] { getScormFileList(scorm: AddonModScormScorm): CoreWSFile[] {
const files: CoreWSExternalFile[] = []; const files: CoreWSFile[] = [];
if (!this.isScormUnsupported(scorm) && !scorm.warningMessage) { if (!this.isScormUnsupported(scorm) && !scorm.warningMessage) {
files.push({ files.push({

View File

@ -18,7 +18,7 @@ import { CoreCourseAnyModuleData } from '@features/course/services/course';
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
import { CoreSitesReadingStrategy } from '@services/sites'; import { CoreSitesReadingStrategy } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { AddonModSurvey, AddonModSurveyProvider } from '../survey'; import { AddonModSurvey, AddonModSurveyProvider } from '../survey';
import { AddonModSurveySync, AddonModSurveySyncResult } from '../survey-sync'; import { AddonModSurveySync, AddonModSurveySyncResult } from '../survey-sync';
@ -37,7 +37,7 @@ export class AddonModSurveyPrefetchHandlerService extends CoreCourseActivityPref
/** /**
* @inheritdoc * @inheritdoc
*/ */
async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreWSExternalFile[]> { async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreWSFile[]> {
const survey = await CoreUtils.ignoreErrors(AddonModSurvey.getSurvey(courseId, module.id)); const survey = await CoreUtils.ignoreErrors(AddonModSurvey.getSurvey(courseId, module.id));
return this.getIntroFilesFromInstance(module, survey); return this.getIntroFilesFromInstance(module, survey);

View File

@ -23,7 +23,7 @@ import { CoreSync } from '@services/sync';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { Translate } from '@singletons'; import { Translate } from '@singletons';
import { CoreEvents } from '@singletons/events'; import { CoreEvents } from '@singletons/events';
import { CoreForms } from '@singletons/form'; 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 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 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 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 originalContent?: string; // The original page content.
protected version?: number; // Page version. protected version?: number; // Page version.
protected renewLockInterval?: number; // An interval to renew the lock every certain time. protected renewLockInterval?: number; // An interval to renew the lock every certain time.

View File

@ -21,7 +21,7 @@ import { CoreGroups } from '@services/groups';
import { CoreFileSizeSum, CorePluginFileDelegate } from '@services/plugin-file-delegate'; import { CoreFileSizeSum, CorePluginFileDelegate } from '@services/plugin-file-delegate';
import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { AddonModWiki, AddonModWikiProvider, AddonModWikiSubwikiPage } from '../wiki'; import { AddonModWiki, AddonModWikiProvider, AddonModWikiSubwikiPage } from '../wiki';
import { AddonModWikiSync, AddonModWikiSyncWikiResult } from '../wiki-sync'; import { AddonModWikiSync, AddonModWikiSyncWikiResult } from '../wiki-sync';
@ -103,7 +103,7 @@ export class AddonModWikiPrefetchHandlerService extends CoreCourseActivityPrefet
courseId: number, courseId: number,
single?: boolean, single?: boolean,
siteId?: string, siteId?: string,
): Promise<CoreWSExternalFile[]> { ): Promise<CoreWSFile[]> {
siteId = siteId || CoreSites.getCurrentSiteId(); siteId = siteId || CoreSites.getCurrentSiteId();
try { try {

View File

@ -22,7 +22,7 @@ import { CoreApp } from '@services/app';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; 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 { makeSingleton, Translate } from '@singletons';
import { CoreEvents } from '@singletons/events'; import { CoreEvents } from '@singletons/events';
import { AddonModWikiPageDBRecord } from './database/wiki'; import { AddonModWikiPageDBRecord } from './database/wiki';
@ -196,7 +196,7 @@ export class AddonModWikiProvider {
* @param options Other options. * @param options Other options.
* @return Promise resolved with subwiki files. * @return Promise resolved with subwiki files.
*/ */
async getSubwikiFiles(wikiId: number, options: AddonModWikiGetSubwikiFilesOptions = {}): Promise<CoreWSExternalFile[]> { async getSubwikiFiles(wikiId: number, options: AddonModWikiGetSubwikiFilesOptions = {}): Promise<CoreWSFile[]> {
const site = await CoreSites.getSite(options.siteId); const site = await CoreSites.getSite(options.siteId);
const groupId = options.groupId || -1; const groupId = options.groupId || -1;
@ -426,10 +426,10 @@ export class AddonModWikiProvider {
* @param options Other options. * @param options Other options.
* @return Promise resolved with the list of files. * @return Promise resolved with the list of files.
*/ */
async getWikiFileList(wiki: AddonModWikiWiki, options: CoreSitesCommonWSOptions = {}): Promise<CoreWSExternalFile[]> { async getWikiFileList(wiki: AddonModWikiWiki, options: CoreSitesCommonWSOptions = {}): Promise<CoreWSFile[]> {
options.siteId = options.siteId || CoreSites.getCurrentSiteId(); options.siteId = options.siteId || CoreSites.getCurrentSiteId();
let files: CoreWSExternalFile[] = []; let files: CoreWSFile[] = [];
const modOptions = { const modOptions = {
cmId: wiki.coursemodule, cmId: wiki.coursemodule,
...options, // Include all options. ...options, // Include all options.

View File

@ -17,7 +17,7 @@ import { Injectable, Type } from '@angular/core';
import { CoreQuestion, CoreQuestionQuestionParsed, CoreQuestionsAnswers } from '@features/question/services/question'; import { CoreQuestion, CoreQuestionQuestionParsed, CoreQuestionsAnswers } from '@features/question/services/question';
import { CoreQuestionHandler } from '@features/question/services/question-delegate'; import { CoreQuestionHandler } from '@features/question/services/question-delegate';
import { CoreQuestionHelper, CoreQuestionQuestion } from '@features/question/services/question-helper'; import { CoreQuestionHelper, CoreQuestionQuestion } from '@features/question/services/question-helper';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { AddonQtypeDdMarkerComponent } from '../../component/ddmarker'; import { AddonQtypeDdMarkerComponent } from '../../component/ddmarker';
@ -135,7 +135,7 @@ export class AddonQtypeDdMarkerHandlerService implements CoreQuestionHandler {
* @param usageId Usage ID. * @param usageId Usage ID.
* @return List of files or URLs. * @return List of files or URLs.
*/ */
getAdditionalDownloadableFiles(question: CoreQuestionQuestionParsed, usageId?: number): CoreWSExternalFile[] { getAdditionalDownloadableFiles(question: CoreQuestionQuestionParsed, usageId?: number): CoreWSFile[] {
const treatedQuestion: CoreQuestionQuestion = question; const treatedQuestion: CoreQuestionQuestion = question;
CoreQuestionHelper.extractQuestionScripts(treatedQuestion, usageId); CoreQuestionHelper.extractQuestionScripts(treatedQuestion, usageId);

View File

@ -20,9 +20,9 @@ import { CoreFileUploaderStoreFilesResult } from '@features/fileuploader/service
import { AddonModQuizEssayQuestion, CoreQuestionBaseComponent } from '@features/question/classes/base-question-component'; import { AddonModQuizEssayQuestion, CoreQuestionBaseComponent } from '@features/question/classes/base-question-component';
import { CoreQuestionHelper } from '@features/question/services/question-helper'; import { CoreQuestionHelper } from '@features/question/services/question-helper';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreWSExternalFile } from '@services/ws';
import { CoreFileSession } from '@services/file-session'; import { CoreFileSession } from '@services/file-session';
import { CoreQuestion } from '@features/question/services/question'; import { CoreQuestion } from '@features/question/services/question';
import { CoreFileEntry } from '@services/file-helper';
/** /**
* Component to render an essay question. * Component to render an essay question.
*/ */
@ -33,7 +33,7 @@ import { CoreQuestion } from '@features/question/services/question';
export class AddonQtypeEssayComponent extends CoreQuestionBaseComponent implements OnInit { export class AddonQtypeEssayComponent extends CoreQuestionBaseComponent implements OnInit {
formControl?: FormControl; formControl?: FormControl;
attachments?: (CoreWSExternalFile | FileEntry)[]; attachments?: CoreFileEntry[];
uploadFilesSupported = false; uploadFilesSupported = false;
essayQuestion?: AddonModQuizEssayQuestion; essayQuestion?: AddonModQuizEssayQuestion;

View File

@ -25,7 +25,7 @@ import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { AddonQtypeEssayComponent } from '../../component/essay'; import { AddonQtypeEssayComponent } from '../../component/essay';
@ -81,12 +81,12 @@ export class AddonQtypeEssayHandlerService implements CoreQuestionHandler {
* @param usageId Usage ID. * @param usageId Usage ID.
* @return List of files or URLs. * @return List of files or URLs.
*/ */
getAdditionalDownloadableFiles(question: CoreQuestionQuestionParsed): CoreWSExternalFile[] { getAdditionalDownloadableFiles(question: CoreQuestionQuestionParsed): CoreWSFile[] {
if (!question.responsefileareas) { if (!question.responsefileareas) {
return []; return [];
} }
return question.responsefileareas.reduce((urlsList, area) => urlsList.concat(area.files || []), <CoreWSExternalFile[]> []); return question.responsefileareas.reduce((urlsList, area) => urlsList.concat(area.files || []), <CoreWSFile[]> []);
} }
/** /**

View File

@ -18,11 +18,11 @@ import { FileEntry } from '@ionic-native/file/ngx';
import { CoreFileUploader, CoreFileUploaderTypeList } from '@features/fileuploader/services/fileuploader'; import { CoreFileUploader, CoreFileUploaderTypeList } from '@features/fileuploader/services/fileuploader';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreWSExternalFile } from '@services/ws';
import { Translate } from '@singletons'; import { Translate } from '@singletons';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreFileUploaderHelper } from '@features/fileuploader/services/fileuploader-helper'; 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. * 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 { 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() 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() 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. @Input() component?: string; // Component the downloaded files will be linked to.

View File

@ -25,7 +25,7 @@ import { CoreUtils } from '@services/utils/utils';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreConstants } from '@/core/constants'; import { CoreConstants } from '@/core/constants';
import { CoreEventObserver, CoreEvents } from '@singletons/events'; 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 * 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 { 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() component?: string; // Component the file belongs to.
@Input() componentId?: string | number; // Component ID. @Input() componentId?: string | number; // Component ID.
@Input() canDelete?: boolean | string; // Whether file can be deleted. @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.alwaysDownload = CoreUtils.isTrueOrOne(this.alwaysDownload);
this.canDownload = CoreUtils.isTrueOrOne(this.canDownload); this.canDownload = CoreUtils.isTrueOrOne(this.canDownload);
this.fileUrl = this.file.fileurl; this.fileUrl = CoreFileHelper.getFileUrl(this.file);
this.timemodified = this.file.timemodified || 0; this.timemodified = this.file.timemodified || 0;
this.siteId = CoreSites.getCurrentSiteId(); this.siteId = CoreSites.getCurrentSiteId();
this.fileSize = this.file.filesize; this.fileSize = this.file.filesize;
@ -88,12 +88,12 @@ export class CoreFileComponent implements OnInit, OnDestroy {
this.showTime = CoreUtils.isTrueOrOne(this.showTime) && this.timemodified > 0; 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.alwaysDownload = true; // Always show the download button in external files.
} }
this.fileIcon = this.file.mimetype ? CoreMimetypeUtils.getMimetypeIcon(this.file.mimetype) : this.fileIcon = 'mimetype' in this.file && this.file.mimetype ?
CoreMimetypeUtils.getFileIcon(this.fileName); CoreMimetypeUtils.getMimetypeIcon(this.file.mimetype) : CoreMimetypeUtils.getFileIcon(this.fileName);
if (this.canDownload) { if (this.canDownload) {
this.calculateState(); this.calculateState();

View File

@ -13,11 +13,10 @@
// limitations under the License. // limitations under the License.
import { Component, Input, OnInit, DoCheck, KeyValueDiffers } from '@angular/core'; 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 { CoreMimetypeUtils } from '@services/utils/mimetype';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalFile } from '@services/ws';
/** /**
* Component to render a file list. * Component to render a file list.
@ -31,7 +30,7 @@ import { CoreWSExternalFile } from '@services/ws';
}) })
export class CoreFilesComponent implements OnInit, DoCheck { 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() component?: string; // Component the downloaded files will be linked to.
@Input() componentId?: string | number; // Component ID. @Input() componentId?: string | number; // Component ID.
@Input() alwaysDownload?: boolean | string; // Whether it should always display the refresh button when the file is downloaded. @Input() alwaysDownload?: boolean | string; // Whether it should always display the refresh button when the file is downloaded.

View File

@ -15,7 +15,7 @@
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
import { CoreFileSizeSum, CorePluginFileDelegate } from '@services/plugin-file-delegate'; import { CoreFileSizeSum, CorePluginFileDelegate } from '@services/plugin-file-delegate';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { CoreCourse, CoreCourseAnyModuleData, CoreCourseModuleContentFile } from '../services/course'; import { CoreCourse, CoreCourseAnyModuleData, CoreCourseModuleContentFile } from '../services/course';
import { CoreCourseModulePrefetchHandler } from '../services/module-prefetch-delegate'; import { CoreCourseModulePrefetchHandler } from '../services/module-prefetch-delegate';
@ -154,7 +154,7 @@ export class CoreCourseModulePrefetchHandlerBase implements CoreCourseModulePref
* @return Promise resolved with the list of files. * @return Promise resolved with the list of files.
*/ */
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
async getFiles(module: CoreCourseAnyModuleData, courseId: number, single?: boolean): Promise<CoreWSExternalFile[]> { async getFiles(module: CoreCourseAnyModuleData, courseId: number, single?: boolean): Promise<CoreWSFile[]> {
// To be overridden. // To be overridden.
return []; return [];
} }
@ -168,7 +168,7 @@ export class CoreCourseModulePrefetchHandlerBase implements CoreCourseModulePref
* @return Promise resolved with list of intro files. * @return Promise resolved with list of intro files.
*/ */
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number, ignoreCache?: boolean): Promise<CoreWSExternalFile[]> { async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number, ignoreCache?: boolean): Promise<CoreWSFile[]> {
return this.getIntroFilesFromInstance(module); 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. * @param instance The instance to get the intro files (book, assign, ...). If not defined, module will be used.
* @return List of intro files. * @return List of intro files.
*/ */
getIntroFilesFromInstance(module: CoreCourseAnyModuleData, instance?: ModuleInstance): CoreWSExternalFile[] { getIntroFilesFromInstance(module: CoreCourseAnyModuleData, instance?: ModuleInstance): CoreWSFile[] {
if (instance) { if (instance) {
if (typeof instance.introfiles != 'undefined') { if (typeof instance.introfiles != 'undefined') {
return instance.introfiles; 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. * Properties a module instance should have to be able to retrieve its intro files.
*/ */
type ModuleInstance = { type ModuleInstance = {
introfiles?: CoreWSExternalFile[]; introfiles?: CoreWSFile[];
intro?: string; intro?: string;
}; };

View File

@ -18,7 +18,7 @@ import { CoreFilterHelper } from '@features/filter/services/filter-helper';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { CoreCourse, CoreCourseAnyModuleData, CoreCourseWSModule } from '../services/course'; import { CoreCourse, CoreCourseAnyModuleData, CoreCourseWSModule } from '../services/course';
import { CoreCourseModulePrefetchHandlerBase } from './module-prefetch-handler'; import { CoreCourseModulePrefetchHandlerBase } from './module-prefetch-handler';
@ -144,7 +144,7 @@ export class CoreCourseResourcePrefetchHandlerBase extends CoreCourseModulePrefe
* @return Promise resolved with the list of files. * @return Promise resolved with the list of files.
*/ */
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
async getFiles(module: CoreCourseWSModule, courseId: number, single?: boolean): Promise<CoreWSExternalFile[]> { async getFiles(module: CoreCourseWSModule, courseId: number, single?: boolean): Promise<CoreWSFile[]> {
// Load module contents if needed. // Load module contents if needed.
await this.loadContents(module, courseId); await this.loadContents(module, courseId);

View File

@ -30,7 +30,7 @@ import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { CoreEvents, CoreEventSectionStatusChangedData } from '@singletons/events'; import { CoreEvents, CoreEventSectionStatusChangedData } from '@singletons/events';
import { CoreError } from '@classes/errors/error'; 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 { CHECK_UPDATES_TIMES_TABLE, CoreCourseCheckUpdatesDBRecord } from './database/module-prefetch';
import { CoreFileSizeSum } from '@services/plugin-file-delegate'; import { CoreFileSizeSum } from '@services/plugin-file-delegate';
@ -458,7 +458,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
// Retrieve file size if it's downloaded. // Retrieve file size if it's downloaded.
await Promise.all(files.map(async (file) => { await Promise.all(files.map(async (file) => {
const path = await CoreFilepool.getFilePathByUrl(siteId, file.fileurl || ''); const path = await CoreFilepool.getFilePathByUrl(siteId, CoreFileHelper.getFileUrl(file));
try { try {
const fileSize = await CoreFile.getFileSize(path); const fileSize = await CoreFile.getFileSize(path);
@ -467,7 +467,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
} catch { } catch {
// Error getting size. Check if the file is being downloaded. // Error getting size. Check if the file is being downloaded.
try { try {
await CoreFilepool.isFileDownloadingByUrl(siteId, file.fileurl || ''); await CoreFilepool.isFileDownloadingByUrl(siteId, CoreFileHelper.getFileUrl(file));
// If downloading, count as downloaded. // If downloading, count as downloaded.
size += file.filesize || 0; size += file.filesize || 0;
@ -523,7 +523,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
async getModuleFiles( async getModuleFiles(
module: CoreCourseAnyModuleData, module: CoreCourseAnyModuleData,
courseId: number, courseId: number,
): Promise<(CoreWSExternalFile | CoreCourseModuleContentFile)[]> { ): Promise<(CoreWSFile | CoreCourseModuleContentFile)[]> {
const handler = this.getPrefetchHandlerFor(module); const handler = this.getPrefetchHandlerFor(module);
if (handler?.getFiles) { if (handler?.getFiles) {
@ -1192,7 +1192,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
const files = await this.getModuleFiles(module, courseId); const files = await this.getModuleFiles(module, courseId);
await Promise.all(files.map(async (file) => { await Promise.all(files.map(async (file) => {
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. * @param courseId Course ID the module belongs to.
* @return List of files, or promise resolved with the files. * @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. * Check if a certain module has updates based on the result of check updates.

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
import { Injectable } from '@angular/core'; 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 { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
import { CoreEvents } from '@singletons/events'; import { CoreEvents } from '@singletons/events';

View File

@ -26,12 +26,13 @@ import { CoreMimetypeUtils } from '@services/utils/mimetype';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreTimeUtils } from '@services/utils/time'; import { CoreTimeUtils } from '@services/utils/time';
import { CoreUtils } from '@services/utils/utils'; 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 { makeSingleton, Translate, MediaCapture, ModalController, Camera } from '@singletons';
import { CoreLogger } from '@singletons/logger'; import { CoreLogger } from '@singletons/logger';
import { CoreEmulatorCaptureMediaComponent } from '@features/emulator/components/capture-media/capture-media'; import { CoreEmulatorCaptureMediaComponent } from '@features/emulator/components/capture-media/capture-media';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
import { CoreSite } from '@classes/site'; import { CoreSite } from '@classes/site';
import { CoreFileEntry, CoreFileHelper } from '@services/file-helper';
/** /**
* File upload options. * File upload options.
@ -80,7 +81,7 @@ export class CoreFileUploaderProvider {
* @param b Second file list. * @param b Second file list.
* @return Whether both lists are different. * @return Whether both lists are different.
*/ */
areFileListDifferent(a: (CoreWSExternalFile | FileEntry)[], b: (CoreWSExternalFile | FileEntry)[]): boolean { areFileListDifferent(a: CoreFileEntry[], b: CoreFileEntry[]): boolean {
a = a || []; a = a || [];
b = b || []; b = b || [];
if (a.length != b.length) { if (a.length != b.length) {
@ -194,7 +195,7 @@ export class CoreFileUploaderProvider {
* *
* @param files List of files. * @param files List of files.
*/ */
clearTmpFiles(files: (CoreWSExternalFile | FileEntry)[]): void { clearTmpFiles(files: (CoreWSFile | FileEntry)[]): void {
// Delete the local files. // Delete the local files.
files.forEach((file) => { files.forEach((file) => {
if ('remove' in file) { if ('remove' in file) {
@ -275,15 +276,16 @@ export class CoreFileUploaderProvider {
* @return List of files to delete. * @return List of files to delete.
*/ */
getFilesToDelete( getFilesToDelete(
originalFiles: CoreWSExternalFile[], originalFiles: CoreWSFile[],
currentFiles: (CoreWSExternalFile | FileEntry)[], currentFiles: CoreFileEntry[],
): { filepath: string; filename: string }[] { ): { filepath: string; filename: string }[] {
const filesToDelete: { filepath: string; filename: string }[] = []; const filesToDelete: { filepath: string; filename: string }[] = [];
currentFiles = currentFiles || []; currentFiles = currentFiles || [];
originalFiles.forEach((file) => { originalFiles.forEach((file) => {
const stillInList = currentFiles.some((currentFile) => (<CoreWSExternalFile> currentFile).fileurl == file.fileurl); const stillInList = currentFiles.some((currentFile) =>
CoreFileHelper.getFileUrl(<CoreWSFile> currentFile) == CoreFileHelper.getFileUrl(file));
if (!stillInList) { if (!stillInList) {
filesToDelete.push({ filesToDelete.push({
@ -391,8 +393,8 @@ export class CoreFileUploaderProvider {
async getStoredFilesFromOfflineFilesObject( async getStoredFilesFromOfflineFilesObject(
filesObject: CoreFileUploaderStoreFilesResult, filesObject: CoreFileUploaderStoreFilesResult,
folderPath: string, folderPath: string,
): Promise<(CoreWSExternalFile | FileEntry)[]> { ): Promise<CoreFileEntry[]> {
let files: (CoreWSExternalFile | FileEntry)[] = []; let files: CoreFileEntry[] = [];
if (filesObject.online.length > 0) { if (filesObject.online.length > 0) {
files = CoreUtils.clone(filesObject.online); files = CoreUtils.clone(filesObject.online);
@ -550,7 +552,7 @@ export class CoreFileUploaderProvider {
*/ */
async storeFilesToUpload( async storeFilesToUpload(
folderPath: string, folderPath: string,
files: (CoreWSExternalFile | FileEntry)[], files: CoreFileEntry[],
): Promise<CoreFileUploaderStoreFilesResult> { ): Promise<CoreFileUploaderStoreFilesResult> {
const result: CoreFileUploaderStoreFilesResult = { const result: CoreFileUploaderStoreFilesResult = {
online: [], online: [],
@ -569,7 +571,7 @@ export class CoreFileUploaderProvider {
// It's an online file, add it to the result and ignore it. // It's an online file, add it to the result and ignore it.
result.online.push({ result.online.push({
filename: file.filename, filename: file.filename,
fileurl: file.fileurl, fileurl: CoreFileHelper.getFileUrl(file),
}); });
} else if (file.fullPath?.indexOf(folderPath) != -1) { } else if (file.fullPath?.indexOf(folderPath) != -1) {
// File already in the submission folder. // File already in the submission folder.
@ -629,7 +631,7 @@ export class CoreFileUploaderProvider {
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @return Promise resolved with the itemId. * @return Promise resolved with the itemId.
*/ */
async uploadFiles(itemId: number, files: (CoreWSExternalFile | FileEntry)[], siteId?: string): Promise<void> { async uploadFiles(itemId: number, files: CoreFileEntry[], siteId?: string): Promise<void> {
siteId = siteId || CoreSites.getCurrentSiteId(); siteId = siteId || CoreSites.getCurrentSiteId();
if (!files || !files.length) { if (!files || !files.length) {
@ -637,7 +639,7 @@ export class CoreFileUploaderProvider {
} }
// Index the online files by name. // Index the online files by name.
const usedNames: {[name: string]: (CoreWSExternalFile | FileEntry)} = {}; const usedNames: {[name: string]: CoreFileEntry} = {};
const filesToUpload: FileEntry[] = []; const filesToUpload: FileEntry[] = [];
files.forEach((file) => { files.forEach((file) => {
if (CoreUtils.isFileEntry(file)) { if (CoreUtils.isFileEntry(file)) {
@ -674,7 +676,7 @@ export class CoreFileUploaderProvider {
* @return Promise resolved with the itemId. * @return Promise resolved with the itemId.
*/ */
async uploadOrReuploadFile( async uploadOrReuploadFile(
file: CoreWSExternalFile | FileEntry, file: CoreFileEntry,
itemId?: number, itemId?: number,
component?: string, component?: string,
componentId?: string | number, componentId?: string | number,
@ -697,7 +699,7 @@ export class CoreFileUploaderProvider {
const path = await CoreFilepool.downloadUrl( const path = await CoreFilepool.downloadUrl(
siteId, siteId,
file.fileurl, CoreFileHelper.getFileUrl(file),
false, false,
component, component,
componentId, componentId,
@ -734,7 +736,7 @@ export class CoreFileUploaderProvider {
* @return Promise resolved with the itemId. * @return Promise resolved with the itemId.
*/ */
async uploadOrReuploadFiles( async uploadOrReuploadFiles(
files: (CoreWSExternalFile | FileEntry)[], files: CoreFileEntry[],
component?: string, component?: string,
componentId?: string | number, componentId?: string | number,
siteId?: string, siteId?: string,
@ -766,7 +768,7 @@ export class CoreFileUploaderProvider {
export const CoreFileUploader = makeSingleton(CoreFileUploaderProvider); export const CoreFileUploader = makeSingleton(CoreFileUploaderProvider);
export type CoreFileUploaderStoreFilesResult = { export type CoreFileUploaderStoreFilesResult = {
online: CoreWSExternalFile[]; // List of online files. online: CoreWSFile[]; // List of online files.
offline: number; // Number of offline files. offline: number; // Number of offline files.
}; };
@ -779,5 +781,3 @@ export type CoreFileUploaderTypeListInfoEntry = {
name?: string; name?: string;
extlist: string; extlist: string;
}; };
export type CoreFileEntry = CoreWSExternalFile | FileEntry;

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { FileEntry } from '@ionic-native/file'; import { FileEntry } from '@ionic-native/file/ngx';
import { CoreFile, CoreFileProvider } from '@services/file'; import { CoreFile, CoreFileProvider } from '@services/file';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';

View File

@ -15,7 +15,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreSites } from '@services/sites'; 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 { CoreTextUtils } from '@services/utils/text';
import { CoreUrlUtils } from '@services/utils/url'; import { CoreUrlUtils } from '@services/utils/url';
import { CoreQueueRunner } from '@classes/queue-runner'; import { CoreQueueRunner } from '@classes/queue-runner';
@ -95,7 +95,7 @@ export class CoreH5PProvider {
options?: CoreH5PGetTrustedFileOptions, options?: CoreH5PGetTrustedFileOptions,
ignoreCache?: boolean, ignoreCache?: boolean,
siteId?: string, siteId?: string,
): Promise<CoreWSExternalFile> { ): Promise<CoreWSFile> {
options = options || {}; options = options || {};

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { FileEntry } from '@ionic-native/file'; import { FileEntry } from '@ionic-native/file/ngx';
import { CoreFilepoolOnProgressCallback } from '@services/filepool'; import { CoreFilepoolOnProgressCallback } from '@services/filepool';
import { CorePluginFileDownloadableResult, CorePluginFileHandler } from '@services/plugin-file-delegate'; import { CorePluginFileDownloadableResult, CorePluginFileHandler } from '@services/plugin-file-delegate';
@ -21,10 +21,11 @@ import { CoreSites } from '@services/sites';
import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreMimetypeUtils } from '@services/utils/mimetype';
import { CoreUrlUtils } from '@services/utils/url'; import { CoreUrlUtils } from '@services/utils/url';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { CoreH5P } from '../h5p'; import { CoreH5P } from '../h5p';
import { Translate, makeSingleton } from '@singletons'; import { Translate, makeSingleton } from '@singletons';
import { CoreH5PHelper } from '../../classes/helper'; import { CoreH5PHelper } from '../../classes/helper';
import { CoreFileHelper } from '@services/file-helper';
/** /**
* Handler to treat H5P files. * Handler to treat H5P files.
@ -54,15 +55,17 @@ export class CoreH5PPluginFileHandlerService implements CorePluginFileHandler {
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @return Promise resolved with the file to use. Rejected if cannot download. * @return Promise resolved with the file to use. Rejected if cannot download.
*/ */
async getDownloadableFile(file: CoreWSExternalFile, siteId?: string): Promise<CoreWSExternalFile> { async getDownloadableFile(file: CoreWSFile, siteId?: string): Promise<CoreWSFile> {
const site = await CoreSites.getSite(siteId); 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. // It's already a deployed file, use it.
return file; 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. * @param siteId Site ID. If not defined, current site.
* @return Promise resolved with the size. * @return Promise resolved with the size.
*/ */
async getFileSize(file: CoreWSExternalFile, siteId?: string): Promise<number> { async getFileSize(file: CoreWSFile, siteId?: string): Promise<number> {
try { try {
const trustedFile = await this.getDownloadableFile(file, siteId); 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. * @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. * @return Promise resolved with a boolean and a reason why it isn't downloadable if needed.
*/ */
async isFileDownloadable(file: CoreWSExternalFile, siteId?: string): Promise<CorePluginFileDownloadableResult> { async isFileDownloadable(file: CoreWSFile, siteId?: string): Promise<CorePluginFileDownloadableResult> {
const offlineDisabled = await CoreH5P.isOfflineDisabled(siteId); const offlineDisabled = await CoreH5P.isOfflineDisabled(siteId);
if (offlineDisabled) { if (offlineDisabled) {
@ -146,8 +149,8 @@ export class CoreH5PPluginFileHandlerService implements CorePluginFileHandler {
* @param file The file data. * @param file The file data.
* @return Whether the file should be treated by this handler. * @return Whether the file should be treated by this handler.
*/ */
shouldHandleFile(file: CoreWSExternalFile): boolean { shouldHandleFile(file: CoreWSFile): boolean {
return CoreMimetypeUtils.guessExtensionFromUrl(file.fileurl) == 'h5p'; return CoreMimetypeUtils.guessExtensionFromUrl(CoreFileHelper.getFileUrl(file)) == 'h5p';
} }
/** /**

View File

@ -18,7 +18,7 @@ import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreUrlUtils } from '@services/utils/url'; import { CoreUrlUtils } from '@services/utils/url';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { CoreLogger } from '@singletons/logger'; import { CoreLogger } from '@singletons/logger';
import { CoreQuestionBehaviourButton, CoreQuestionHelper, CoreQuestionQuestion } from '../services/question-helper'; import { CoreQuestionBehaviourButton, CoreQuestionHelper, CoreQuestionQuestion } from '../services/question-helper';
@ -715,7 +715,7 @@ export type AddonModQuizEssayQuestion = AddonModQuizQuestionBasicData & {
isPlainText?: boolean; // Whether the answer is plain text. isPlainText?: boolean; // Whether the answer is plain text.
hasInlineText?: boolean; // // Whether the answer has inline text hasInlineText?: boolean; // // Whether the answer has inline text
answer?: string; // Question answer text. answer?: string; // Question answer text.
attachments?: CoreWSExternalFile[]; // Question answer attachments. attachments?: CoreWSFile[]; // Question answer attachments.
hasDraftFiles?: boolean; // Whether the question has draft files. hasDraftFiles?: boolean; // Whether the question has draft files.
textarea?: AddonModQuizQuestionTextarea; // Textarea data. textarea?: AddonModQuizQuestionTextarea; // Textarea data.
formatInput?: { name: string; value: string }; // Format input data. formatInput?: { name: string; value: string }; // Format input data.

View File

@ -15,7 +15,7 @@
import { Injectable, Type } from '@angular/core'; import { Injectable, Type } from '@angular/core';
import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate'; import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { CoreQuestionDefaultHandler } from './handlers/default-question'; import { CoreQuestionDefaultHandler } from './handlers/default-question';
import { CoreQuestionQuestionParsed, CoreQuestionsAnswers } from './question'; import { CoreQuestionQuestionParsed, CoreQuestionsAnswers } from './question';
@ -143,7 +143,7 @@ export interface CoreQuestionHandler extends CoreDelegateHandler {
* @param usageId Usage ID. * @param usageId Usage ID.
* @return List of files or URLs. * @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. * Clear temporary data after the data has been saved.
@ -393,7 +393,7 @@ export class CoreQuestionDelegateService extends CoreDelegate<CoreQuestionHandle
* @param usageId Usage ID. * @param usageId Usage ID.
* @return List of files or URLs. * @return List of files or URLs.
*/ */
getAdditionalDownloadableFiles(question: CoreQuestionQuestionParsed, usageId?: number): CoreWSExternalFile[] { getAdditionalDownloadableFiles(question: CoreQuestionQuestionParsed, usageId?: number): CoreWSFile[] {
const type = this.getTypeName(question); const type = this.getTypeName(question);
return this.executeFunctionOnEnabled(type, 'getAdditionalDownloadableFiles', [question, usageId]) || []; return this.executeFunctionOnEnabled(type, 'getAdditionalDownloadableFiles', [question, usageId]) || [];

View File

@ -15,13 +15,14 @@
import { Injectable, EventEmitter } from '@angular/core'; import { Injectable, EventEmitter } from '@angular/core';
import { CoreFile } from '@services/file'; import { CoreFile } from '@services/file';
import { CoreFileHelper } from '@services/file-helper';
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreUrlUtils } from '@services/utils/url'; import { CoreUrlUtils } from '@services/utils/url';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton, Translate } from '@singletons'; import { makeSingleton, Translate } from '@singletons';
import { CoreQuestion, CoreQuestionProvider, CoreQuestionQuestionParsed, CoreQuestionsAnswers } from './question'; import { CoreQuestion, CoreQuestionProvider, CoreQuestionQuestionParsed, CoreQuestionsAnswers } from './question';
import { CoreQuestionDelegate } from './question-delegate'; import { CoreQuestionDelegate } from './question-delegate';
@ -394,7 +395,7 @@ export class CoreQuestionHelperProvider {
* @param html HTML code to search in. * @param html HTML code to search in.
* @return Attachments. * @return Attachments.
*/ */
getQuestionAttachmentsFromHtml(html: string): CoreWSExternalFile[] { getQuestionAttachmentsFromHtml(html: string): CoreWSFile[] {
const element = CoreDomUtils.convertToElement(html); const element = CoreDomUtils.convertToElement(html);
// Remove the filemanager (area to attach files to a question). // Remove the filemanager (area to attach files to a question).
@ -402,7 +403,7 @@ export class CoreQuestionHelperProvider {
// Search the anchors. // Search the anchors.
const anchors = Array.from(element.querySelectorAll('a')); const anchors = Array.from(element.querySelectorAll('a'));
const attachments: CoreWSExternalFile[] = []; const attachments: CoreWSFile[] = [];
anchors.forEach((anchor) => { anchors.forEach((anchor) => {
let content = anchor.innerHTML; let content = anchor.innerHTML;
@ -464,7 +465,7 @@ export class CoreQuestionHelperProvider {
* @param areaName Name of the area, e.g. 'attachments'. * @param areaName Name of the area, e.g. 'attachments'.
* @return List of files. * @return List of files.
*/ */
getResponseFileAreaFiles(question: CoreQuestionQuestion, areaName: string): CoreWSExternalFile[] { getResponseFileAreaFiles(question: CoreQuestionQuestion, areaName: string): CoreWSFile[] {
if (!question.responsefileareas) { if (!question.responsefileareas) {
return []; return [];
} }
@ -642,22 +643,23 @@ export class CoreQuestionHelperProvider {
await Promise.all(files.map(async (file) => { await Promise.all(files.map(async (file) => {
const timemodified = file.timemodified || 0; const timemodified = file.timemodified || 0;
const fileUrl = CoreFileHelper.getFileUrl(file);
if (treated[file.fileurl]) { if (treated[fileUrl]) {
return; return;
} }
treated[file.fileurl] = true; treated[fileUrl] = true;
if (!site.canDownloadFiles() && CoreUrlUtils.isPluginFileUrl(file.fileurl)) { if (!site.canDownloadFiles() && CoreUrlUtils.isPluginFileUrl(fileUrl)) {
return; 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. // Ignore flag images.
return; return;
} }
await CoreFilepool.addToQueueByUrl(site.getId(), file.fileurl, component, componentId, timemodified); await CoreFilepool.addToQueueByUrl(site.getId(), fileUrl, component, componentId, timemodified);
})); }));
} }

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
import { Component, OnInit, Input } from '@angular/core'; 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 { CoreFile } from '@services/file';
import { ModalController, Translate } from '@singletons'; import { ModalController, Translate } from '@singletons';

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
import { Component, OnInit, OnDestroy, Input, Output, EventEmitter } from '@angular/core'; 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 { IonRefresher } from '@ionic/angular';
import { Md5 } from 'ts-md5'; import { Md5 } from 'ts-md5';

View File

@ -14,7 +14,7 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { CoreSharedFilesHelper } from '@features/sharedfiles/services/sharedfiles-helper'; 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 { CoreFile } from '@services/file';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { CoreSiteBasicInfo, CoreSites } from '@services/sites'; import { CoreSiteBasicInfo, CoreSites } from '@services/sites';

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
import { Injectable } from '@angular/core'; 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 { CoreCanceledError } from '@classes/errors/cancelederror';
import { CoreFileUploader } from '@features/fileuploader/services/fileuploader'; import { CoreFileUploader } from '@features/fileuploader/services/fileuploader';

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
import { Injectable } from '@angular/core'; 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 { Md5 } from 'ts-md5/dist/md5';
import { SQLiteDB } from '@classes/sqlitedb'; import { SQLiteDB } from '@classes/sqlitedb';

View File

@ -13,10 +13,9 @@
// limitations under the License. // limitations under the License.
import { Component, Input } from '@angular/core'; 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 { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalFile } from '@services/ws';
import { ModalController } from '@singletons'; import { ModalController } from '@singletons';
/** /**
@ -32,7 +31,7 @@ export class CoreViewerTextComponent {
@Input() content?: string; // Modal content. @Input() content?: string; // Modal content.
@Input() component?: string; // Component to use in format-text. @Input() component?: string; // Component to use in format-text.
@Input() componentId?: string | number; // Component ID 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() filter?: boolean; // Whether to filter the text.
@Input() contextLevel?: string; // The context level. @Input() contextLevel?: string; // The context level.
@Input() instanceId?: number; // The instance ID related to the context. @Input() instanceId?: number; // The instance ID related to the context.

View File

@ -13,13 +13,13 @@
// limitations under the License. // limitations under the License.
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { FileEntry } from '@ionic-native/file'; import { FileEntry } from '@ionic-native/file/ngx';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreFile } from '@services/file'; import { CoreFile } from '@services/file';
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreWS, CoreWSExternalFile } from '@services/ws'; import { CoreWS, CoreWSFile } from '@services/ws';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreUrlUtils } from '@services/utils/url'; import { CoreUrlUtils } from '@services/utils/url';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
@ -46,7 +46,7 @@ export class CoreFileHelperProvider {
* @return Resolved on success. * @return Resolved on success.
*/ */
async downloadAndOpenFile( async downloadAndOpenFile(
file: CoreWSExternalFile, file: CoreWSFile,
component?: string, component?: string,
componentId?: string | number, componentId?: string | number,
state?: string, state?: string,
@ -55,7 +55,7 @@ export class CoreFileHelperProvider {
): Promise<void> { ): Promise<void> {
siteId = siteId || CoreSites.getCurrentSiteId(); siteId = siteId || CoreSites.getCurrentSiteId();
const fileUrl = file.fileurl; const fileUrl = CoreFileHelper.getFileUrl(file);
const timemodified = this.getFileTimemodified(file); const timemodified = this.getFileTimemodified(file);
if (!this.isOpenableInApp(file)) { if (!this.isOpenableInApp(file)) {
@ -119,7 +119,7 @@ export class CoreFileHelperProvider {
* @return Resolved with the URL to use on success. * @return Resolved with the URL to use on success.
*/ */
protected async downloadFileIfNeeded( protected async downloadFileIfNeeded(
file: CoreWSExternalFile, file: CoreWSFile,
fileUrl: string, fileUrl: string,
component?: string, component?: string,
componentId?: string | number, componentId?: string | number,
@ -215,7 +215,7 @@ export class CoreFileHelperProvider {
componentId?: string | number, componentId?: string | number,
timemodified?: number, timemodified?: number,
onProgress?: (event: ProgressEvent) => void, onProgress?: (event: ProgressEvent) => void,
file?: CoreWSExternalFile, file?: CoreWSFile,
siteId?: string, siteId?: string,
): Promise<string> { ): Promise<string> {
siteId = siteId || CoreSites.getCurrentSiteId(); siteId = siteId || CoreSites.getCurrentSiteId();
@ -255,10 +255,10 @@ export class CoreFileHelperProvider {
* Get the file's URL. * Get the file's URL.
* *
* @param file The file. * @param file The file.
* @deprecated since 3.9.5. Get directly the fileurl instead. * @return File URL.
*/ */
getFileUrl(file: CoreWSExternalFile): string | undefined { getFileUrl(file: CoreWSFile): string {
return file.fileurl; return 'fileurl' in file ? file.fileurl : file.url;
} }
/** /**
@ -266,7 +266,7 @@ export class CoreFileHelperProvider {
* *
* @param file The file. * @param file The file.
*/ */
getFileTimemodified(file: CoreWSExternalFile): number { getFileTimemodified(file: CoreWSFile): number {
return file.timemodified || 0; return file.timemodified || 0;
} }
@ -286,8 +286,8 @@ export class CoreFileHelperProvider {
* @param file The file to check. * @param file The file to check.
* @return Whether the file should be opened in browser. * @return Whether the file should be opened in browser.
*/ */
shouldOpenInBrowser(file: CoreWSExternalFile): boolean { shouldOpenInBrowser(file: CoreWSFile): boolean {
if (!file || !file.isexternalfile || !file.mimetype) { if (!file || !('isexternalfile' in file) || !file.isexternalfile || !file.mimetype) {
return false; return false;
} }
@ -312,7 +312,7 @@ export class CoreFileHelperProvider {
* @param files The files to check. * @param files The files to check.
* @return Total files size. * @return Total files size.
*/ */
async getTotalFilesSize(files: (CoreWSExternalFile | FileEntry)[]): Promise<number> { async getTotalFilesSize(files: CoreFileEntry[]): Promise<number> {
let totalSize = 0; let totalSize = 0;
for (const file of files) { for (const file of files) {
@ -328,14 +328,14 @@ export class CoreFileHelperProvider {
* @param file The file to check. * @param file The file to check.
* @return File size. * @return File size.
*/ */
async getFileSize(file: CoreWSExternalFile | FileEntry): Promise<number> { async getFileSize(file: CoreFileEntry): Promise<number> {
if ('filesize' in file && (file.filesize || file.filesize === 0)) { if ('filesize' in file && (file.filesize || file.filesize === 0)) {
return file.filesize; return file.filesize;
} }
// If it's a remote file. First check if we have the file downloaded since it's more reliable. // If it's a remote file. First check if we have the file downloaded since it's more reliable.
if ('filename' in file) { if ('filename' in file) {
const fileUrl = file.fileurl; const fileUrl = CoreFileHelper.getFileUrl(file);
try { try {
const siteId = CoreSites.getCurrentSiteId(); const siteId = CoreSites.getCurrentSiteId();
@ -422,3 +422,5 @@ export class CoreFileHelperProvider {
export const CoreFileHelper = makeSingleton(CoreFileHelperProvider); export const CoreFileHelper = makeSingleton(CoreFileHelperProvider);
export type CoreFileHelperOnProgress = (event?: ProgressEvent | { calculating: true }) => void; export type CoreFileHelperOnProgress = (event?: ProgressEvent | { calculating: true }) => void;
export type CoreFileEntry = CoreWSFile | FileEntry;

View File

@ -13,10 +13,9 @@
// limitations under the License. // limitations under the License.
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { FileEntry } from '@ionic-native/file'; import { CoreFileEntry } from '@services/file-helper';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreWSExternalFile } from '@services/ws';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
/** /**
@ -29,7 +28,7 @@ import { makeSingleton } from '@singletons';
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class CoreFileSessionProvider { 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. * Add a file to the session.
@ -39,7 +38,7 @@ export class CoreFileSessionProvider {
* @param file File to add. * @param file File to add.
* @param siteId Site ID. If not defined, current site. * @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(); siteId = siteId || CoreSites.getCurrentSiteId();
this.initFileArea(component, id, siteId); this.initFileArea(component, id, siteId);
@ -69,7 +68,7 @@ export class CoreFileSessionProvider {
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @return Array of files in session. * @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(); siteId = siteId || CoreSites.getCurrentSiteId();
if (this.files[siteId] && this.files[siteId][component] && this.files[siteId][component][id]) { if (this.files[siteId] && this.files[siteId][component] && this.files[siteId][component][id]) {
return 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 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. * @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(); siteId = siteId || CoreSites.getCurrentSiteId();
if (this.files[siteId] && this.files[siteId][component] && this.files[siteId][component][id]) { if (this.files[siteId] && this.files[siteId][component] && this.files[siteId][component][id]) {
const position = this.files[siteId][component][id].indexOf(file); const position = this.files[siteId][component][id].indexOf(file);
@ -141,7 +140,7 @@ export class CoreFileSessionProvider {
* @param newFiles Files to set. * @param newFiles Files to set.
* @param siteId Site ID. If not defined, current site. * @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(); siteId = siteId || CoreSites.getCurrentSiteId();
this.initFileArea(component, id, siteId); this.initFileArea(component, id, siteId);

View File

@ -14,10 +14,9 @@
import { Injectable } from '@angular/core'; 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 { CoreApp } from '@services/app';
import { CoreWSExternalFile } from '@services/ws';
import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreMimetypeUtils } from '@services/utils/mimetype';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
@ -26,6 +25,7 @@ import { CoreError } from '@classes/errors/error';
import { CoreLogger } from '@singletons/logger'; import { CoreLogger } from '@singletons/logger';
import { makeSingleton, File, Zip, Platform, WebView } from '@singletons'; 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. * Progress event used when writing a file data into a file.
@ -1177,7 +1177,7 @@ export class CoreFileProvider {
* @param files List of used files. * @param files List of used files.
* @return Promise resolved when done, rejected if failure. * @return Promise resolved when done, rejected if failure.
*/ */
async removeUnusedFiles(dirPath: string, files: (CoreWSExternalFile | FileEntry)[]): Promise<void> { async removeUnusedFiles(dirPath: string, files: CoreFileEntry[]): Promise<void> {
// Get the directory contents. // Get the directory contents.
try { try {
const contents = await this.getDirectoryContents(dirPath); const contents = await this.getDirectoryContents(dirPath);
@ -1297,7 +1297,7 @@ export class CoreFileProvider {
* @param file The file. * @param file The file.
* @return The file name. * @return The file name.
*/ */
getFileName(file: CoreWSExternalFile | FileEntry): string | undefined { getFileName(file: CoreFileEntry): string | undefined {
return CoreUtils.isFileEntry(file) ? file.name : file.filename; return CoreUtils.isFileEntry(file) ? file.name : file.filename;
} }

View File

@ -20,7 +20,7 @@ import { CoreEventPackageStatusChanged, CoreEvents } from '@singletons/events';
import { CoreFile } from '@services/file'; import { CoreFile } from '@services/file';
import { CorePluginFileDelegate } from '@services/plugin-file-delegate'; import { CorePluginFileDelegate } from '@services/plugin-file-delegate';
import { CoreSites } from '@services/sites'; 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 { CoreDomUtils } from '@services/utils/dom';
import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreMimetypeUtils } from '@services/utils/mimetype';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
@ -46,6 +46,7 @@ import {
CoreFilepoolQueueEntry, CoreFilepoolQueueEntry,
CoreFilepoolQueueDBEntry, CoreFilepoolQueueDBEntry,
} from '@services/database/filepool'; } from '@services/database/filepool';
import { CoreFileHelper } from './file-helper';
/* /*
* Factory for handling downloading files and retrieve downloaded files. * 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<void> { async addFileLinkByUrl(siteId: string, fileUrl: string, component: string, componentId?: string | number): Promise<void> {
const file = await this.fixPluginfileURL(siteId, fileUrl); 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); 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). * @param componentId An ID to use in conjunction with the component (optional).
* @return Resolved on success. * @return Resolved on success.
*/ */
addFilesToQueue(siteId: string, files: CoreWSExternalFile[], component?: string, componentId?: string | number): Promise<void> { addFilesToQueue(siteId: string, files: CoreWSFile[], component?: string, componentId?: string | number): Promise<void> {
return this.downloadOrPrefetchFiles(siteId, files, true, false, component, componentId); return this.downloadOrPrefetchFiles(siteId, files, true, false, component, componentId);
} }
@ -342,7 +343,7 @@ export class CoreFilepoolProvider {
// Fix the URL and use the fixed data. // Fix the URL and use the fixed data.
const file = await this.fixPluginfileURL(siteId, fileUrl); const file = await this.fixPluginfileURL(siteId, fileUrl);
fileUrl = file.fileurl; fileUrl = CoreFileHelper.getFileUrl(file);
timemodified = file.timemodified || timemodified; timemodified = file.timemodified || timemodified;
} }
@ -735,7 +736,7 @@ export class CoreFilepoolProvider {
*/ */
downloadOrPrefetchFiles( downloadOrPrefetchFiles(
siteId: string, siteId: string,
files: CoreWSExternalFile[], files: CoreWSFile[],
prefetch: boolean, prefetch: boolean,
ignoreStale?: boolean, ignoreStale?: boolean,
component?: string, component?: string,
@ -746,11 +747,11 @@ export class CoreFilepoolProvider {
// Download files. // Download files.
files.forEach((file) => { files.forEach((file) => {
const url = file.fileurl; const url = CoreFileHelper.getFileUrl(file);
const timemodified = file.timemodified; const timemodified = file.timemodified;
const options = { const options = {
isexternalfile: file.isexternalfile, isexternalfile: 'isexternalfile' in file ? file.isexternalfile : undefined,
repositorytype: file.repositorytype, repositorytype: 'repositorytype' in file ? file.repositorytype : undefined,
}; };
let path: string | undefined; let path: string | undefined;
@ -799,7 +800,7 @@ export class CoreFilepoolProvider {
*/ */
downloadOrPrefetchPackage( downloadOrPrefetchPackage(
siteId: string, siteId: string,
fileList: CoreWSExternalFile[], fileList: CoreWSFile[],
prefetch: boolean, prefetch: boolean,
component: string, component: string,
componentId?: string | number, componentId?: string | number,
@ -822,10 +823,10 @@ export class CoreFilepoolProvider {
let packageLoaded = 0; let packageLoaded = 0;
fileList.forEach((file) => { fileList.forEach((file) => {
const fileUrl = file.fileurl; const fileUrl = CoreFileHelper.getFileUrl(file);
const options = { const options = {
isexternalfile: file.isexternalfile, isexternalfile: 'isexternalfile' in file ? file.isexternalfile : undefined,
repositorytype: file.repositorytype, repositorytype: 'repositorytype' in file ? file.repositorytype : undefined,
}; };
let path: string | undefined; let path: string | undefined;
let promise: Promise<string | void>; let promise: Promise<string | void>;
@ -924,7 +925,7 @@ export class CoreFilepoolProvider {
*/ */
downloadPackage( downloadPackage(
siteId: string, siteId: string,
fileList: CoreWSExternalFile[], fileList: CoreWSFile[],
component: string, component: string,
componentId?: string | number, componentId?: string | number,
extra?: string, extra?: string,
@ -973,7 +974,7 @@ export class CoreFilepoolProvider {
} }
const file = await this.fixPluginfileURL(siteId, fileUrl); const file = await this.fixPluginfileURL(siteId, fileUrl);
fileUrl = file.fileurl; fileUrl = CoreFileHelper.getFileUrl(file);
timemodified = file.timemodified || timemodified; timemodified = file.timemodified || timemodified;
options = Object.assign({}, options); // Create a copy to prevent modifying the original object. 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. * @param timemodified The timemodified of the file.
* @return Promise resolved with the file data to use. * @return Promise resolved with the file data to use.
*/ */
protected async fixPluginfileURL(siteId: string, fileUrl: string, timemodified: number = 0): Promise<CoreWSExternalFile> { protected async fixPluginfileURL(siteId: string, fileUrl: string, timemodified: number = 0): Promise<CoreWSFile> {
const file = await CorePluginFileDelegate.getDownloadableFile({ fileurl: fileUrl, timemodified }); const file = await CorePluginFileDelegate.getDownloadableFile({ fileurl: fileUrl, timemodified });
const site = await CoreSites.getSite(siteId); 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; return file;
} }
@ -1206,7 +1211,7 @@ export class CoreFilepoolProvider {
} }
const file = await this.fixPluginfileURL(siteId, fileUrl); 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 filePath = await this.getFilePath(siteId, fileId, '');
const dirEntry = await CoreFile.getDir(filePath); const dirEntry = await CoreFile.getDir(filePath);
@ -1244,7 +1249,7 @@ export class CoreFilepoolProvider {
*/ */
getFileEventNameByUrl(siteId: string, fileUrl: string): Promise<string> { getFileEventNameByUrl(siteId: string, fileUrl: string): Promise<string> {
return this.fixPluginfileURL(siteId, fileUrl).then((file) => { 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); return this.getFileEventName(siteId, fileId);
}); });
@ -1342,7 +1347,7 @@ export class CoreFilepoolProvider {
*/ */
async getFilePathByUrl(siteId: string, fileUrl: string): Promise<string> { async getFilePathByUrl(siteId: string, fileUrl: string): Promise<string> {
const file = await this.fixPluginfileURL(siteId, fileUrl); 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); return this.getFilePath(siteId, fileId);
} }
@ -1433,7 +1438,7 @@ export class CoreFilepoolProvider {
filePath?: string, filePath?: string,
revision?: number, revision?: number,
): Promise<string> { ): Promise<string> {
let file: CoreWSExternalFile; let file: CoreWSFile;
try { try {
file = await this.fixPluginfileURL(siteId, fileUrl, timemodified); file = await this.fixPluginfileURL(siteId, fileUrl, timemodified);
@ -1441,7 +1446,7 @@ export class CoreFilepoolProvider {
return CoreConstants.NOT_DOWNLOADABLE; return CoreConstants.NOT_DOWNLOADABLE;
} }
fileUrl = file.fileurl; fileUrl = CoreFileHelper.getFileUrl(file);
timemodified = file.timemodified || timemodified; timemodified = file.timemodified || timemodified;
revision = revision || this.getRevisionFromUrl(fileUrl); revision = revision || this.getRevisionFromUrl(fileUrl);
const fileId = this.getFileIdByUrl(fileUrl); const fileId = this.getFileIdByUrl(fileUrl);
@ -1527,7 +1532,7 @@ export class CoreFilepoolProvider {
const file = await this.fixPluginfileURL(siteId, fileUrl, timemodified); const file = await this.fixPluginfileURL(siteId, fileUrl, timemodified);
fileUrl = file.fileurl; fileUrl = CoreFileHelper.getFileUrl(file);
timemodified = file.timemodified || timemodified; timemodified = file.timemodified || timemodified;
revision = revision || this.getRevisionFromUrl(fileUrl); revision = revision || this.getRevisionFromUrl(fileUrl);
const fileId = this.getFileIdByUrl(fileUrl); const fileId = this.getFileIdByUrl(fileUrl);
@ -1635,7 +1640,7 @@ export class CoreFilepoolProvider {
} }
const file = await this.fixPluginfileURL(siteId, fileUrl); 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); return this.getInternalUrlById(siteId, fileId);
} }
@ -1693,7 +1698,7 @@ export class CoreFilepoolProvider {
*/ */
getPackageDirPathByUrl(siteId: string, url: string): Promise<string> { getPackageDirPathByUrl(siteId: string, url: string): Promise<string> {
return this.fixPluginfileURL(siteId, url).then((file) => { 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, ''); return this.getFilePath(siteId, dirName, '');
}); });
@ -1712,7 +1717,7 @@ export class CoreFilepoolProvider {
} }
const file = await this.fixPluginfileURL(siteId, url); 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 dirPath = await this.getFilePath(siteId, dirName, '');
const dirEntry = await CoreFile.getDir(dirPath); const dirEntry = await CoreFile.getDir(dirPath);
@ -1890,12 +1895,14 @@ export class CoreFilepoolProvider {
* @param files Package files. * @param files Package files.
* @return Highest revision. * @return Highest revision.
*/ */
getRevisionFromFileList(files: CoreWSExternalFile[]): number { getRevisionFromFileList(files: CoreWSFile[]): number {
let revision = 0; let revision = 0;
files.forEach((file) => { files.forEach((file) => {
if (file.fileurl) { const fileUrl = CoreFileHelper.getFileUrl(file);
const r = this.getRevisionFromUrl(file.fileurl);
if (fileUrl) {
const r = this.getRevisionFromUrl(fileUrl);
if (r > revision) { if (r > revision) {
revision = r; revision = r;
} }
@ -1981,7 +1988,7 @@ export class CoreFilepoolProvider {
* @param files List of files. * @param files List of files.
* @return Time modified. * @return Time modified.
*/ */
getTimemodifiedFromFileList(files: CoreWSExternalFile[]): number { getTimemodifiedFromFileList(files: CoreWSFile[]): number {
let timemodified = 0; let timemodified = 0;
files.forEach((file) => { files.forEach((file) => {
@ -2163,7 +2170,7 @@ export class CoreFilepoolProvider {
*/ */
async invalidateFileByUrl(siteId: string, fileUrl: string): Promise<void> { async invalidateFileByUrl(siteId: string, fileUrl: string): Promise<void> {
const file = await this.fixPluginfileURL(siteId, fileUrl); 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); const db = await CoreSites.getSiteDb(siteId);
@ -2250,7 +2257,7 @@ export class CoreFilepoolProvider {
*/ */
async isFileDownloadingByUrl(siteId: string, fileUrl: string): Promise<void> { async isFileDownloadingByUrl(siteId: string, fileUrl: string): Promise<void> {
const file = await this.fixPluginfileURL(siteId, fileUrl); 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); await this.hasFileInQueue(siteId, fileId);
} }
@ -2403,7 +2410,7 @@ export class CoreFilepoolProvider {
*/ */
prefetchPackage( prefetchPackage(
siteId: string, siteId: string,
fileList: CoreWSExternalFile[], fileList: CoreWSFile[],
component: string, component: string,
componentId?: string | number, componentId?: string | number,
extra?: string, extra?: string,
@ -2691,7 +2698,7 @@ export class CoreFilepoolProvider {
*/ */
async removeFileByUrl(siteId: string, fileUrl: string): Promise<void> { async removeFileByUrl(siteId: string, fileUrl: string): Promise<void> {
const file = await this.fixPluginfileURL(siteId, fileUrl); 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); await this.removeFileById(siteId, fileId);
} }

View File

@ -13,14 +13,15 @@
// limitations under the License. // limitations under the License.
import { Injectable } from '@angular/core'; 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 { CoreFilepool, CoreFilepoolOnProgressCallback } from '@services/filepool';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { CoreConstants } from '@/core/constants'; import { CoreConstants } from '@/core/constants';
import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate'; import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { CoreSites } from './sites'; import { CoreSites } from './sites';
import { CoreFileHelper } from './file-helper';
/** /**
* Delegate to register pluginfile information handlers. * Delegate to register pluginfile information handlers.
@ -57,7 +58,7 @@ export class CorePluginFileDelegateService extends CoreDelegate<CorePluginFileHa
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @return Promise resolved with the file to use. Rejected if cannot download. * @return Promise resolved with the file to use. Rejected if cannot download.
*/ */
getDownloadableFile(file: CoreWSExternalFile, siteId?: string): Promise<CoreWSExternalFile> { getDownloadableFile(file: CoreWSFile, siteId?: string): Promise<CoreWSFile> {
const handler = this.getHandlerForFile(file); const handler = this.getHandlerForFile(file);
return this.getHandlerDownloadableFile(file, handler, siteId); return this.getHandlerDownloadableFile(file, handler, siteId);
@ -72,10 +73,10 @@ export class CorePluginFileDelegateService extends CoreDelegate<CorePluginFileHa
* @return Promise resolved with the file to use. Rejected if cannot download. * @return Promise resolved with the file to use. Rejected if cannot download.
*/ */
protected async getHandlerDownloadableFile( protected async getHandlerDownloadableFile(
file: CoreWSExternalFile, file: CoreWSFile,
handler?: CorePluginFileHandler, handler?: CorePluginFileHandler,
siteId?: string, siteId?: string,
): Promise<CoreWSExternalFile> { ): Promise<CoreWSFile> {
const isDownloadable = await this.isFileDownloadable(file, siteId); const isDownloadable = await this.isFileDownloadable(file, siteId);
if (!isDownloadable.downloadable) { if (!isDownloadable.downloadable) {
@ -134,13 +135,13 @@ export class CorePluginFileDelegateService extends CoreDelegate<CorePluginFileHa
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @return Promise resolved with file size and a boolean to indicate if it is the total size or only partial. * @return Promise resolved with file size and a boolean to indicate if it is the total size or only partial.
*/ */
async getFilesDownloadSize(files: CoreWSExternalFile[], siteId?: string): Promise<CoreFileSizeSum> { async getFilesDownloadSize(files: CoreWSFile[], siteId?: string): Promise<CoreFileSizeSum> {
siteId = siteId || CoreSites.getCurrentSiteId(); siteId = siteId || CoreSites.getCurrentSiteId();
const filteredFiles = <CoreWSExternalFile[]>[]; const filteredFiles = <CoreWSFile[]>[];
await Promise.all(files.map(async (file) => { 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) { if (state != CoreConstants.DOWNLOADED && state != CoreConstants.NOT_DOWNLOADABLE) {
filteredFiles.push(file); filteredFiles.push(file);
@ -157,7 +158,7 @@ export class CorePluginFileDelegateService extends CoreDelegate<CorePluginFileHa
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @return Promise resolved with file size and a boolean to indicate if it is the total size or only partial. * @return Promise resolved with file size and a boolean to indicate if it is the total size or only partial.
*/ */
async getFilesSize(files: CoreWSExternalFile[], siteId?: string): Promise<CoreFileSizeSum> { async getFilesSize(files: CoreWSFile[], siteId?: string): Promise<CoreFileSizeSum> {
const result = { const result = {
size: 0, size: 0,
total: true, total: true,
@ -184,7 +185,7 @@ export class CorePluginFileDelegateService extends CoreDelegate<CorePluginFileHa
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @return Promise resolved with the size. * @return Promise resolved with the size.
*/ */
async getFileSize(file: CoreWSExternalFile, siteId?: string): Promise<number> { async getFileSize(file: CoreWSFile, siteId?: string): Promise<number> {
const isDownloadable = await this.isFileDownloadable(file, siteId); const isDownloadable = await this.isFileDownloadable(file, siteId);
if (!isDownloadable.downloadable) { if (!isDownloadable.downloadable) {
@ -218,7 +219,7 @@ export class CorePluginFileDelegateService extends CoreDelegate<CorePluginFileHa
* @param file File data. * @param file File data.
* @return Handler. * @return Handler.
*/ */
protected getHandlerForFile(file: CoreWSExternalFile): CorePluginFileHandler | undefined { protected getHandlerForFile(file: CoreWSFile): CorePluginFileHandler | undefined {
for (const component in this.enabledHandlers) { for (const component in this.enabledHandlers) {
const handler = this.enabledHandlers[component]; const handler = this.enabledHandlers[component];
@ -235,7 +236,7 @@ export class CorePluginFileDelegateService extends CoreDelegate<CorePluginFileHa
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @return Promise with the data. * @return Promise with the data.
*/ */
async isFileDownloadable(file: CoreWSExternalFile, siteId?: string): Promise<CorePluginFileDownloadableResult> { async isFileDownloadable(file: CoreWSFile, siteId?: string): Promise<CorePluginFileDownloadableResult> {
const handler = this.getHandlerForFile(file); const handler = this.getHandlerForFile(file);
if (handler && handler.isFileDownloadable) { if (handler && handler.isFileDownloadable) {
@ -337,7 +338,7 @@ export interface CorePluginFileHandler extends CoreDelegateHandler {
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @return Promise resolved with the file to use. Rejected if cannot download. * @return Promise resolved with the file to use. Rejected if cannot download.
*/ */
getDownloadableFile?(file: CoreWSExternalFile, siteId?: string): Promise<CoreWSExternalFile>; getDownloadableFile?(file: CoreWSFile, siteId?: string): Promise<CoreWSFile>;
/** /**
* Given an HTML element, get the URLs of the files that should be downloaded and weren't treated by * 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. * @param siteId Site ID. If not defined, current site.
* @return Promise resolved with the size. * @return Promise resolved with the size.
*/ */
getFileSize?(file: CoreWSExternalFile, siteId?: string): Promise<number>; getFileSize?(file: CoreWSFile, siteId?: string): Promise<number>;
/** /**
* Check if a file is downloadable. * Check if a file is downloadable.
@ -364,7 +365,7 @@ export interface CorePluginFileHandler extends CoreDelegateHandler {
* @param siteId Site ID. If not defined, current site. * @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. * @return Promise resolved with a boolean and a reason why it isn't downloadable if needed.
*/ */
isFileDownloadable?(file: CoreWSExternalFile, siteId?: string): Promise<CorePluginFileDownloadableResult>; isFileDownloadable?(file: CoreWSFile, siteId?: string): Promise<CorePluginFileDownloadableResult>;
/** /**
* Check whether the file should be treated by this handler. It is used in functions where the component isn't used. * 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. * @param file The file data.
* @return Whether the file should be treated by this handler. * @return Whether the file should be treated by this handler.
*/ */
shouldHandleFile?(file: CoreWSExternalFile): boolean; shouldHandleFile?(file: CoreWSFile): boolean;
/** /**
* Treat a downloaded file. * Treat a downloaded file.

View File

@ -13,17 +13,18 @@
// limitations under the License. // limitations under the License.
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { FileEntry } from '@ionic-native/file'; import { FileEntry } from '@ionic-native/file/ngx';
import { CoreFile } from '@services/file'; import { CoreFile } from '@services/file';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { makeSingleton, Translate } from '@singletons'; import { makeSingleton, Translate } from '@singletons';
import { CoreLogger } from '@singletons/logger'; import { CoreLogger } from '@singletons/logger';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import extToMime from '@/assets/exttomime.json'; import extToMime from '@/assets/exttomime.json';
import mimeToExt from '@/assets/mimetoext.json'; import mimeToExt from '@/assets/mimetoext.json';
import { CoreFileEntry, CoreFileHelper } from '@services/file-helper';
interface MimeTypeInfo { interface MimeTypeInfo {
type: string; type: string;
@ -163,7 +164,7 @@ export class CoreMimetypeUtilsProvider {
* @param file File object. * @param file File object.
* @param path Alternative path that will override fileurl from 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 filename = CoreUtils.isFileEntry(file) ? (file as FileEntry).name : file.filename;
const extension = !CoreUtils.isFileEntry(file) && file.mimetype const extension = !CoreUtils.isFileEntry(file) && file.mimetype
? this.getExtension(file.mimetype) ? this.getExtension(file.mimetype)
@ -173,7 +174,7 @@ export class CoreMimetypeUtilsProvider {
: (extension && this.getMimeType(extension)); : (extension && this.getMimeType(extension));
// @todo linting: See if this can be removed // @todo linting: See if this can be removed
(file as CoreWSExternalFile).mimetype = mimeType; (file as CoreWSFile).mimetype = mimeType;
if (extension && this.canBeEmbedded(extension)) { if (extension && this.canBeEmbedded(extension)) {
const embedType = this.getExtensionType(extension); const embedType = this.getExtensionType(extension);
@ -181,7 +182,7 @@ export class CoreMimetypeUtilsProvider {
// @todo linting: See if this can be removed // @todo linting: See if this can be removed
(file as { embedType?: string }).embedType = embedType; (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); path = path && CoreFile.convertFileSrc(path);
switch (embedType) { switch (embedType) {
@ -401,7 +402,7 @@ export class CoreMimetypeUtilsProvider {
* @param capitalise If true, capitalises first character of result. * @param capitalise If true, capitalises first character of result.
* @return Type description. * @return Type description.
*/ */
getMimetypeDescription(obj: FileEntry | CoreWSExternalFile | string, capitalise?: boolean): string { getMimetypeDescription(obj: CoreFileEntry | string, capitalise?: boolean): string {
const langPrefix = 'assets.mimetypes.'; const langPrefix = 'assets.mimetypes.';
let filename: string | undefined = ''; let filename: string | undefined = '';
let mimetype: string | undefined = ''; let mimetype: string | undefined = '';

View File

@ -20,9 +20,10 @@ import { CoreApp } from '@services/app';
import { CoreLang } from '@services/lang'; import { CoreLang } from '@services/lang';
import { CoreAnyError, CoreError } from '@classes/errors/error'; import { CoreAnyError, CoreError } from '@classes/errors/error';
import { makeSingleton, ModalController, Translate } from '@singletons'; import { makeSingleton, ModalController, Translate } from '@singletons';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { Locutus } from '@singletons/locutus'; import { Locutus } from '@singletons/locutus';
import { CoreViewerTextComponent } from '@features/viewer/components/text/text'; import { CoreViewerTextComponent } from '@features/viewer/components/text/text';
import { CoreFileHelper } from '@services/file-helper';
/** /**
* Different type of errors the app can treat. * Different type of errors the app can treat.
@ -462,7 +463,7 @@ export class CoreTextUtilsProvider {
text: string, text: string,
component?: string, component?: string,
componentId?: string | number, componentId?: string | number,
files?: CoreWSExternalFile[], files?: CoreWSFile[],
filter?: boolean, filter?: boolean,
contextLevel?: string, contextLevel?: string,
instanceId?: number, 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. * @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. * @return Pluginfile URL, undefined if no files found.
*/ */
getTextPluginfileUrl(files: CoreWSExternalFile[]): string | undefined { getTextPluginfileUrl(files: CoreWSFile[]): string | undefined {
if (files?.length) { if (files?.length) {
const url = files[0].fileurl; const url = CoreFileHelper.getFileUrl(files[0]);
// Remove text after last slash (encoded or not). // Remove text after last slash (encoded or not).
return url?.substr(0, Math.max(url.lastIndexOf('/'), url.lastIndexOf('%2F'))); return url?.substr(0, Math.max(url.lastIndexOf('/'), url.lastIndexOf('%2F')));
@ -759,7 +760,7 @@ export class CoreTextUtilsProvider {
replaceDraftfileUrls( replaceDraftfileUrls(
siteUrl: string, siteUrl: string,
text: string, text: string,
files: CoreWSExternalFile[], files: CoreWSFile[],
): { text: string; replaceMap?: {[url: string]: string} } { ): { text: string; replaceMap?: {[url: string]: string} } {
if (!text || !files || !files.length) { if (!text || !files || !files.length) {
@ -776,7 +777,7 @@ export class CoreTextUtilsProvider {
// Index the pluginfile URLs by file name. // Index the pluginfile URLs by file name.
const pluginfileMap: {[name: string]: string} = {}; const pluginfileMap: {[name: string]: string} = {};
files.forEach((file) => { files.forEach((file) => {
pluginfileMap[file.filename!] = file.fileurl; pluginfileMap[file.filename!] = CoreFileHelper.getFileUrl(file);
}); });
// Replace each draftfile with the corresponding pluginfile URL. // 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. * @param files Files to extract the pluginfile URL from. They need to have the URL in a url or fileurl attribute.
* @return Treated text. * @return Treated text.
*/ */
replacePluginfileUrls(text: string, files: CoreWSExternalFile[]): string { replacePluginfileUrls(text: string, files: CoreWSFile[]): string {
if (text && typeof text == 'string') { if (text && typeof text == 'string') {
const fileURL = this.getTextPluginfileUrl(files); const fileURL = this.getTextPluginfileUrl(files);
if (fileURL) { if (fileURL) {
@ -830,7 +831,7 @@ export class CoreTextUtilsProvider {
* @param replaceMap Map of the replacements that were done. * @param replaceMap Map of the replacements that were done.
* @return Treated text. * @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) { if (!treatedText || !files || !files.length) {
return treatedText; return treatedText;
} }
@ -848,7 +849,7 @@ export class CoreTextUtilsProvider {
return; // Original URL not found, skip. 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; 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. * @param files Files to extract the pluginfile URL from. They need to have the URL in a url or fileurl attribute.
* @return Treated text. * @return Treated text.
*/ */
restorePluginfileUrls(text: string, files: CoreWSExternalFile[]): string { restorePluginfileUrls(text: string, files: CoreWSFile[]): string {
if (text && typeof text == 'string') { if (text && typeof text == 'string') {
const fileURL = this.getTextPluginfileUrl(files); const fileURL = this.getTextPluginfileUrl(files);
if (fileURL) { if (fileURL) {
@ -1103,7 +1104,7 @@ export class CoreTextUtilsProvider {
export type CoreTextUtilsViewTextOptions = { export type CoreTextUtilsViewTextOptions = {
component?: string; // Component to link the embedded files to. component?: string; // Component to link the embedded files to.
componentId?: string | number; // An ID to use in conjunction with the component. 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. filter?: boolean; // Whether the text should be filtered.
contextLevel?: string; // The context level. contextLevel?: string; // The context level.
instanceId?: number; // The instance ID related to the context. instanceId?: number; // The instance ID related to the context.

View File

@ -14,14 +14,14 @@
import { Injectable, NgZone } from '@angular/core'; import { Injectable, NgZone } from '@angular/core';
import { InAppBrowserObject, InAppBrowserOptions } from '@ionic-native/in-app-browser'; 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 { Subscription } from 'rxjs';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreEvents } from '@singletons/events'; import { CoreEvents } from '@singletons/events';
import { CoreFile } from '@services/file'; import { CoreFile } from '@services/file';
import { CoreLang } from '@services/lang'; import { CoreLang } from '@services/lang';
import { CoreWS, CoreWSExternalFile } from '@services/ws'; import { CoreWS, CoreWSFile } from '@services/ws';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreMimetypeUtils } from '@services/utils/mimetype';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
@ -31,6 +31,7 @@ import { CoreLogger } from '@singletons/logger';
import { CoreFileSizeSum } from '@services/plugin-file-delegate'; import { CoreFileSizeSum } from '@services/plugin-file-delegate';
import { CoreViewerQRScannerComponent } from '@features/viewer/components/qr-scanner/qr-scanner'; import { CoreViewerQRScannerComponent } from '@features/viewer/components/qr-scanner/qr-scanner';
import { CoreCanceledError } from '@classes/errors/cancelederror'; import { CoreCanceledError } from '@classes/errors/cancelederror';
import { CoreFileEntry } from '@services/file-helper';
type TreeNode<T> = T & { children: TreeNode<T>[] }; type TreeNode<T> = T & { children: TreeNode<T>[] };
@ -379,11 +380,7 @@ export class CoreUtilsProvider {
/** /**
* Execute promises one depending on the previous. * Execute promises one depending on the previous.
* *
* @param orderedPromisesData Data to be executed including the following values: * @param orderedPromisesData Data to be executed.
* - 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.
* @return Promise resolved when all promises are resolved. * @return Promise resolved when all promises are resolved.
*/ */
executeOrderedPromises(orderedPromisesData: OrderedPromiseData[]): Promise<void> { executeOrderedPromises(orderedPromisesData: OrderedPromiseData[]): Promise<void> {
@ -748,7 +745,7 @@ export class CoreUtilsProvider {
* @param file File. * @param file File.
* @return Type guard indicating if the file is a FileEntry. * @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; return 'isFile' in file;
} }
@ -768,7 +765,7 @@ export class CoreUtilsProvider {
* @param files List of files. * @param files List of files.
* @return String with error message if repeated, false if no repeated. * @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) { if (!files || !files.length) {
return false; 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. * @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. * @deprecated since 3.8.0. Use CorePluginFileDelegate.getFilesSize instead.
*/ */
sumFileSizes(files: CoreWSExternalFile[]): CoreFileSizeSum { sumFileSizes(files: CoreWSFile[]): CoreFileSizeSum {
const result = { const result = {
size: 0, size: 0,
total: true, total: true,

View File

@ -15,7 +15,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { HttpResponse, HttpParams } from '@angular/common/http'; 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 { FileUploadOptions } from '@ionic-native/file-transfer/ngx';
import { Md5 } from 'ts-md5/dist/md5'; import { Md5 } from 'ts-md5/dist/md5';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
@ -1087,6 +1087,43 @@ export type CoreWSExternalFile = {
repositorytype?: string; // The repository type for external files. 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. * Data returned by date_exporter.
*/ */