MOBILE-3657 file: Add uploadOrStoreFile overloads

main
Pau Ferrer Ocaña 2021-04-16 10:12:47 +02:00
parent 8d31beb0a7
commit e024947fdd
5 changed files with 88 additions and 15 deletions

View File

@ -694,16 +694,40 @@ export class AddonModAssignHelperProvider {
assignId: number,
folderName: string,
files: CoreFileEntry[],
offline = false,
offline: true,
userId?: number,
siteId?: string,
): Promise<CoreFileUploaderStoreFilesResult>;
async uploadOrStoreFiles(
assignId: number,
folderName: string,
files: CoreFileEntry[],
offline: false,
userId?: number,
siteId?: string,
): Promise<number>;
async uploadOrStoreFiles(
assignId: number,
folderName: string,
files: CoreFileEntry[],
offline: boolean,
userId?: number,
siteId?: string,
): Promise<number | CoreFileUploaderStoreFilesResult>;
async uploadOrStoreFiles(
assignId: number,
folderName: string,
files: CoreFileEntry[],
offline: boolean,
userId?: number,
siteId?: string,
): Promise<number | CoreFileUploaderStoreFilesResult> {
if (offline) {
return await this.storeSubmissionFiles(assignId, folderName, files, userId, siteId);
return this.storeSubmissionFiles(assignId, folderName, files, userId, siteId);
}
return await this.uploadFiles(assignId, files, siteId);
return this.uploadFiles(assignId, files, siteId);
}
}

View File

@ -278,7 +278,7 @@ export class AddonModAssignSubmissionFileHandlerService implements AddonModAssig
plugin: AddonModAssignPlugin,
inputData: AddonModAssignSubmissionFileData,
pluginData: AddonModAssignSubmissionFilePluginData,
offline?: boolean,
offline = false,
userId?: number,
siteId?: string,
): Promise<void> {

View File

@ -542,7 +542,7 @@ export class AddonModDataHelperProvider {
dataId: number,
entryId: number,
entryContents: AddonModDataEntryFields,
offline: boolean = false,
offline = false,
siteId?: string,
): Promise<AddonModDataEntryWSField[]> {
if (!inputData) {
@ -766,6 +766,33 @@ export class AddonModDataHelperProvider {
* @param siteId Site ID. If not defined, current site.
* @return Promise resolved with the itemId for the uploaded file/s.
*/
async uploadOrStoreFiles(
dataId: number,
itemId: number,
entryId: number,
fieldId: number,
files: CoreFileEntry[],
offline: true,
siteId?: string,
): Promise<CoreFileUploaderStoreFilesResult>;
async uploadOrStoreFiles(
dataId: number,
itemId: number,
entryId: number,
fieldId: number,
files: CoreFileEntry[],
offline: false,
siteId?: string,
): Promise<number>;
async uploadOrStoreFiles(
dataId: number,
itemId: number,
entryId: number,
fieldId: number,
files: CoreFileEntry[],
offline: boolean,
siteId?: string,
): Promise<number | CoreFileUploaderStoreFilesResult>;
async uploadOrStoreFiles(
dataId: number,
itemId: number = 0,

View File

@ -287,7 +287,7 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
const attachment = await AddonModForumHelper.uploadOrStoreReplyFiles(
this.forum.id,
this.post.id,
files,
files as CoreFileEntry[],
false,
);

View File

@ -445,11 +445,17 @@ export class AddonModForumHelperProvider {
* @param userId User the reply belongs to. If not defined, current user in site.
* @return Promise resolved if success, rejected otherwise.
*/
async storeReplyFiles(forumId: number, postId: number, files: any[], siteId?: string, userId?: number): Promise<void> {
async storeReplyFiles(
forumId: number,
postId: number,
files: CoreFileEntry[],
siteId?: string,
userId?: number,
): Promise<CoreFileUploaderStoreFilesResult> {
// Get the folder where to store the files.
const folderPath = await AddonModForumOffline.getReplyFolder(forumId, postId, siteId, userId);
await CoreFileUploader.storeFilesToUpload(folderPath, files);
return CoreFileUploader.storeFilesToUpload(folderPath, files);
}
/**
@ -485,9 +491,9 @@ export class AddonModForumHelperProvider {
): Promise<CoreFileUploaderStoreFilesResult | number> {
if (offline) {
return this.storeNewDiscussionFiles(forumId, timecreated, files, siteId);
} else {
return CoreFileUploader.uploadOrReuploadFiles(files, AddonModForumProvider.COMPONENT, forumId, siteId);
}
return CoreFileUploader.uploadOrReuploadFiles(files, AddonModForumProvider.COMPONENT, forumId, siteId);
}
/**
@ -501,19 +507,35 @@ export class AddonModForumHelperProvider {
* @param userId User the reply belongs to. If not defined, current user in site.
* @return Promise resolved if success.
*/
uploadOrStoreReplyFiles(
async uploadOrStoreReplyFiles(
forumId: number,
postId: number,
files: any[],
files: CoreFileEntry[],
offline: true,
siteId?: string,
userId?: number,
): Promise<CoreFileUploaderStoreFilesResult>;
async uploadOrStoreReplyFiles(
forumId: number,
postId: number,
files: CoreFileEntry[],
offline: false,
siteId?: string,
userId?: number,
): Promise<number>;
async uploadOrStoreReplyFiles(
forumId: number,
postId: number,
files: CoreFileEntry[],
offline: boolean,
siteId?: string,
userId?: number,
): Promise<any> {
): Promise<CoreFileUploaderStoreFilesResult | number> {
if (offline) {
return this.storeReplyFiles(forumId, postId, files, siteId, userId);
} else {
return CoreFileUploader.uploadOrReuploadFiles(files, AddonModForumProvider.COMPONENT, forumId, siteId);
}
return CoreFileUploader.uploadOrReuploadFiles(files, AddonModForumProvider.COMPONENT, forumId, siteId);
}
}