Skip to content

Commit

Permalink
Issue #SB-66923 feat: content sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
balakrishna-m committed Jan 3, 2020
1 parent 282bd6b commit a8aa994
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/content/def/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export interface ContentImport {
export interface ContentExportRequest {
destinationFolder: string;
contentIds: string[];
saveLocally?: boolean;
}

export interface ContentMarkerRequest {
Expand Down
9 changes: 8 additions & 1 deletion src/content/handlers/export/copy-to-destination.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { Response } from '../../../api';
import {FileUtil} from '../../../util/file/util/file-util';
import { ContentExportRequest } from '../..';

export class CopyToDestination {

constructor() {
}

public async execute(exportResponse: Response, destinationFolder): Promise<Response> {
public async execute(exportResponse: Response, contentExportRequest: ContentExportRequest): Promise<Response> {
return new Promise<Response>((resolve, reject) => {
let destinationFolder;
if (contentExportRequest.saveLocally) {
destinationFolder = contentExportRequest.destinationFolder;
} else {
destinationFolder = cordova.file.externalCacheDirectory;
}
buildconfigreader.copyFile(FileUtil.getDirecory(exportResponse.body.ecarFilePath), destinationFolder,
FileUtil.getFileName(exportResponse.body.ecarFilePath),
() => {
Expand Down
22 changes: 22 additions & 0 deletions src/content/handlers/export/deletete-temp-dir.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {Response} from '../../../api';
import {ExportContentContext} from '../..';

export class DeleteTempDir {

constructor() {
}

public async execute(exportContext: ExportContentContext): Promise<Response> {
const response: Response = new Response();
return new Promise<Response>((resolve, reject) => {
const tmpDirPath = exportContext.destinationFolder!.concat('tmp/');
buildconfigreader.rm(tmpDirPath, '', () => {
response.body = exportContext;
resolve(response);
}, (e) => {
response.body = exportContext;
resolve(response);
});
});
}
}
12 changes: 9 additions & 3 deletions src/content/handlers/export/generate-export-share-telemetry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ContentExportResponse, ExportContentContext} from '../..';
import {ContentExportResponse, ExportContentContext, ContentExportRequest} from '../..';
import {Response} from '../../../api';
import {Item, ShareDirection, ShareItemType, ShareType, TelemetryService, TelemetryShareRequest} from '../../../telemetry';
import {ContentUtil} from '../../util/content-util';
Expand All @@ -7,7 +7,7 @@ export class GenerateExportShareTelemetry {
constructor(private telemetryService: TelemetryService) {
}

execute(exportContentContext: ExportContentContext): Promise<Response> {
execute(exportContentContext: ExportContentContext, fileName: string, contentExportRequest: ContentExportRequest): Promise<Response> {
const response: Response = new Response();
const items: Item[] = [];
for (const element of exportContentContext.items!) {
Expand All @@ -28,7 +28,13 @@ export class GenerateExportShareTelemetry {
};
return this.telemetryService.share(req).toPromise()
.then(() => {
const exportResponse: ContentExportResponse = {exportedFilePath: exportContentContext.ecarFilePath!};
let exportedFilePath;
if (contentExportRequest.saveLocally) {
exportedFilePath = contentExportRequest.destinationFolder.concat(fileName);
} else {
exportedFilePath = cordova.file.externalCacheDirectory.concat(fileName);
}
const exportResponse: ContentExportResponse = {exportedFilePath: exportedFilePath};
response.body = exportResponse;
return Promise.resolve(response);
}).catch(() => {
Expand Down
18 changes: 12 additions & 6 deletions src/content/impl/content-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ import {DeviceInfo} from '../../util/device';
import {GetContentHeirarchyHandler} from './../handlers/get-content-heirarchy-handler';
import {catchError, map, mapTo, mergeMap, take} from 'rxjs/operators';
import { CopyToDestination } from '../handlers/export/copy-to-destination';
import { DeleteTempDir } from './../handlers/export/deletete-temp-dir';

@injectable()
export class ContentServiceImpl implements ContentService, DownloadCompleteDelegate, SdkServiceOnInitDelegate {
Expand Down Expand Up @@ -277,9 +278,9 @@ export class ContentServiceImpl implements ContentService, DownloadCompleteDeleg
contentModelsToExport: contentsInDb,
tmpLocationPath: tempLocationPath.nativeURL
};
return new CleanTempLoc(this.fileService).execute(exportContentContext);
}).then((exportResponse: Response) => {
return new CreateTempLoc(this.fileService).execute(exportResponse.body);
// return new CleanTempLoc(this.fileService).execute(exportContentContext);
// }).then((exportResponse: Response) => {
return new CreateTempLoc(this.fileService).execute(exportContentContext);
}).then((exportResponse: Response) => {
return new CreateContentExportManifest(this.dbService, exportHandler).execute(exportResponse.body);
}).then((exportResponse: Response) => {
Expand All @@ -293,11 +294,16 @@ export class ContentServiceImpl implements ContentService, DownloadCompleteDeleg
}).then((exportResponse: Response) => {
return new EcarBundle(this.fileService, this.zipService).execute(exportResponse.body);
}).then((exportResponse: Response) => {
return new CopyToDestination().execute(exportResponse, contentExportRequest.destinationFolder);
return new CopyToDestination().execute(exportResponse, contentExportRequest);
// }).then((exportResponse: Response) => {
// return new DeleteTempEcar(this.fileService).execute(exportResponse.body);
}).then((exportResponse: Response) => {
return new DeleteTempEcar(this.fileService).execute(exportResponse.body);
return new DeleteTempDir().execute(exportResponse.body);
}).then((exportResponse: Response) => {
return new GenerateExportShareTelemetry(this.telemetryService).execute(exportResponse.body);
const fileName = ContentUtil.getExportedFileName(contentsInDb);
return new GenerateExportShareTelemetry(
this.telemetryService).execute(exportResponse.body, fileName, contentExportRequest
);
}).then((exportResponse: Response<ContentExportResponse>) => {
return exportResponse.body;
});
Expand Down

0 comments on commit a8aa994

Please sign in to comment.