MOBILE-3947 native: Fix zip plugin
parent
9a5329cdc3
commit
7325a1dd6d
|
@ -39,7 +39,6 @@
|
||||||
"@awesome-cordova-plugins/sqlite": "^6.3.0",
|
"@awesome-cordova-plugins/sqlite": "^6.3.0",
|
||||||
"@awesome-cordova-plugins/status-bar": "^6.3.0",
|
"@awesome-cordova-plugins/status-bar": "^6.3.0",
|
||||||
"@awesome-cordova-plugins/web-intent": "^6.3.0",
|
"@awesome-cordova-plugins/web-intent": "^6.3.0",
|
||||||
"@awesome-cordova-plugins/zip": "^6.3.0",
|
|
||||||
"@ionic/angular": "^7.0.0",
|
"@ionic/angular": "^7.0.0",
|
||||||
"@ionic/cordova-builders": "^10.0.0",
|
"@ionic/cordova-builders": "^10.0.0",
|
||||||
"@moodlehq/cordova-plugin-advanced-http": "3.3.1-moodle.1",
|
"@moodlehq/cordova-plugin-advanced-http": "3.3.1-moodle.1",
|
||||||
|
@ -1034,18 +1033,6 @@
|
||||||
"rxjs": "^5.5.0 || ^6.5.0 || ^7.3.0"
|
"rxjs": "^5.5.0 || ^6.5.0 || ^7.3.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@awesome-cordova-plugins/zip": {
|
|
||||||
"version": "6.4.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/@awesome-cordova-plugins/zip/-/zip-6.4.0.tgz",
|
|
||||||
"integrity": "sha512-s6Bg+sBepwhVvN+8fdns8QOOY5Mo5pg9Iy1aJiFDBUipuQOLaO++zw5u+no0igObnYcaQAdSO2XyEBX/h0T59g==",
|
|
||||||
"dependencies": {
|
|
||||||
"@types/cordova": "latest"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"@awesome-cordova-plugins/core": "^6.0.1",
|
|
||||||
"rxjs": "^5.5.0 || ^6.5.0 || ^7.3.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@babel/code-frame": {
|
"node_modules/@babel/code-frame": {
|
||||||
"version": "7.23.4",
|
"version": "7.23.4",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.23.4.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.23.4.tgz",
|
||||||
|
|
|
@ -74,7 +74,6 @@
|
||||||
"@awesome-cordova-plugins/sqlite": "^6.3.0",
|
"@awesome-cordova-plugins/sqlite": "^6.3.0",
|
||||||
"@awesome-cordova-plugins/status-bar": "^6.3.0",
|
"@awesome-cordova-plugins/status-bar": "^6.3.0",
|
||||||
"@awesome-cordova-plugins/web-intent": "^6.3.0",
|
"@awesome-cordova-plugins/web-intent": "^6.3.0",
|
||||||
"@awesome-cordova-plugins/zip": "^6.3.0",
|
|
||||||
"@ionic/angular": "^7.0.0",
|
"@ionic/angular": "^7.0.0",
|
||||||
"@ionic/cordova-builders": "^10.0.0",
|
"@ionic/cordova-builders": "^10.0.0",
|
||||||
"@moodlehq/cordova-plugin-advanced-http": "3.3.1-moodle.1",
|
"@moodlehq/cordova-plugin-advanced-http": "3.3.1-moodle.1",
|
||||||
|
|
|
@ -27,7 +27,7 @@ import { Geolocation } from '@awesome-cordova-plugins/geolocation/ngx';
|
||||||
import { InAppBrowser } from '@awesome-cordova-plugins/in-app-browser/ngx';
|
import { InAppBrowser } from '@awesome-cordova-plugins/in-app-browser/ngx';
|
||||||
import { LocalNotifications } from '@awesome-cordova-plugins/local-notifications/ngx';
|
import { LocalNotifications } from '@awesome-cordova-plugins/local-notifications/ngx';
|
||||||
import { MediaCapture } from '@awesome-cordova-plugins/media-capture/ngx';
|
import { MediaCapture } from '@awesome-cordova-plugins/media-capture/ngx';
|
||||||
import { Zip } from '@awesome-cordova-plugins/zip/ngx';
|
import { Zip } from '@features/native/plugins/zip';
|
||||||
|
|
||||||
// Mock services.
|
// Mock services.
|
||||||
import { CameraMock } from './services/camera';
|
import { CameraMock } from './services/camera';
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Zip } from '@awesome-cordova-plugins/zip/ngx';
|
import { Zip } from '@features/native/plugins/zip';
|
||||||
import * as JSZip from 'jszip';
|
import * as JSZip from 'jszip';
|
||||||
import { CorePath } from '@singletons/path';
|
import { CorePath } from '@singletons/path';
|
||||||
import { File } from '@singletons';
|
import { File } from '@singletons';
|
||||||
|
@ -50,12 +50,10 @@ export class ZipMock extends Zip {
|
||||||
*
|
*
|
||||||
* @param source Path to the source ZIP file.
|
* @param source Path to the source ZIP file.
|
||||||
* @param destination Destination folder.
|
* @param destination Destination folder.
|
||||||
* @param onProgressFunction Optional callback to be called on progress update
|
* @param onProgress Optional callback to be called on progress update
|
||||||
* @returns Promise that resolves with a number. 0 is success, -1 is error.
|
* @returns Promise that resolves with a number. 0 is success, -1 is error.
|
||||||
*/
|
*/
|
||||||
async unzip(source: string, destination: string, onProgressFunction?: Function): Promise<number> {
|
async unzip(source: string, destination: string, onProgress?: (ev: {loaded: number; total: number}) => void): Promise<number> {
|
||||||
const onProgress = onProgressFunction as (ev: {loaded: number; total: number}) => void;
|
|
||||||
|
|
||||||
// Replace all %20 with spaces.
|
// Replace all %20 with spaces.
|
||||||
source = source.replace(/%20/g, ' ');
|
source = source.replace(/%20/g, ' ');
|
||||||
destination = destination.replace(/%20/g, ' ');
|
destination = destination.replace(/%20/g, ' ');
|
||||||
|
|
|
@ -36,7 +36,7 @@ import { SplashScreen } from '@awesome-cordova-plugins/splash-screen/ngx';
|
||||||
import { SQLite } from '@awesome-cordova-plugins/sqlite/ngx';
|
import { SQLite } from '@awesome-cordova-plugins/sqlite/ngx';
|
||||||
import { StatusBar } from '@awesome-cordova-plugins/status-bar/ngx';
|
import { StatusBar } from '@awesome-cordova-plugins/status-bar/ngx';
|
||||||
import { WebIntent } from '@awesome-cordova-plugins/web-intent/ngx';
|
import { WebIntent } from '@awesome-cordova-plugins/web-intent/ngx';
|
||||||
import { Zip } from '@awesome-cordova-plugins/zip/ngx';
|
import { Zip } from '@features/native/plugins/zip';
|
||||||
|
|
||||||
export const CORE_NATIVE_SERVICES = [
|
export const CORE_NATIVE_SERVICES = [
|
||||||
Badge,
|
Badge,
|
||||||
|
@ -87,7 +87,6 @@ export const CORE_NATIVE_SERVICES = [
|
||||||
StatusBar,
|
StatusBar,
|
||||||
WebIntent,
|
WebIntent,
|
||||||
WebView,
|
WebView,
|
||||||
Zip,
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class CoreNativeModule {}
|
export class CoreNativeModule {}
|
||||||
|
|
|
@ -14,5 +14,7 @@
|
||||||
|
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
import { Chooser as ChooserService } from './chooser';
|
import { Chooser as ChooserService } from './chooser';
|
||||||
|
import { Zip as ZipService } from './zip';
|
||||||
|
|
||||||
export const Chooser = makeSingleton(ChooserService);
|
export const Chooser = makeSingleton(ChooserService);
|
||||||
|
export const Zip = makeSingleton(ZipService);
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zip plugin wrapper.
|
||||||
|
*/
|
||||||
|
@Injectable({ providedIn: 'root' })
|
||||||
|
export class Zip {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts files from a ZIP archive
|
||||||
|
*
|
||||||
|
* @param source Source ZIP file
|
||||||
|
* @param destination Destination folder
|
||||||
|
* @param onProgress Callback to be called on progress update
|
||||||
|
* @returns 0 is success, -1 is error
|
||||||
|
*/
|
||||||
|
unzip(source: string, destination: string, onProgress?: (ev: {loaded: number; total: number}) => void): Promise<number> {
|
||||||
|
return new Promise(resolve => window.zip.unzip(source, destination, (result: number) => resolve(result), onProgress));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -58,7 +58,6 @@ import { StatusBar as StatusBarService } from '@awesome-cordova-plugins/status-b
|
||||||
import { SplashScreen as SplashScreenService } from '@awesome-cordova-plugins/splash-screen/ngx';
|
import { SplashScreen as SplashScreenService } from '@awesome-cordova-plugins/splash-screen/ngx';
|
||||||
import { SQLite as SQLiteService } from '@awesome-cordova-plugins/sqlite/ngx';
|
import { SQLite as SQLiteService } from '@awesome-cordova-plugins/sqlite/ngx';
|
||||||
import { WebIntent as WebIntentService } from '@awesome-cordova-plugins/web-intent/ngx';
|
import { WebIntent as WebIntentService } from '@awesome-cordova-plugins/web-intent/ngx';
|
||||||
import { Zip as ZipService } from '@awesome-cordova-plugins/zip/ngx';
|
|
||||||
|
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
|
||||||
|
@ -192,7 +191,6 @@ export const SplashScreen = makeSingleton(SplashScreenService);
|
||||||
export const SQLite = makeSingleton(SQLiteService);
|
export const SQLite = makeSingleton(SQLiteService);
|
||||||
export const WebIntent = makeSingleton(WebIntentService);
|
export const WebIntent = makeSingleton(WebIntentService);
|
||||||
export const WebView = makeSingleton(WebViewService);
|
export const WebView = makeSingleton(WebViewService);
|
||||||
export const Zip = makeSingleton(ZipService);
|
|
||||||
|
|
||||||
export const Camera = makeSingleton(CameraService);
|
export const Camera = makeSingleton(CameraService);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Types for file cordova plugin.
|
||||||
|
*
|
||||||
|
* @see https://github.com/moodlemobile/cordova-plugin-zip
|
||||||
|
*/
|
||||||
|
|
||||||
|
interface Window {
|
||||||
|
|
||||||
|
zip: {
|
||||||
|
unzip(source: string, destination: string, onSuccess: Function, onProgress?: Function): void;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue