react-native-cloud-storage 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +33 -0
- package/app.plugin.js +1 -0
- package/ios/CloudStorage-Bridging-Header.h +2 -0
- package/ios/CloudStorage.m +19 -0
- package/ios/CloudStorage.swift +98 -0
- package/ios/CloudStorage.xcodeproj/project.pbxproj +283 -0
- package/lib/commonjs/RNCloudStorage.js +53 -0
- package/lib/commonjs/RNCloudStorage.js.map +1 -0
- package/lib/commonjs/createRNCloudStorage.js +27 -0
- package/lib/commonjs/createRNCloudStorage.js.map +1 -0
- package/lib/commonjs/expo-plugin/withRNCloudStorage.js +14 -0
- package/lib/commonjs/expo-plugin/withRNCloudStorage.js.map +1 -0
- package/lib/commonjs/expo-plugin/withRNCloudStorageIos.js +39 -0
- package/lib/commonjs/expo-plugin/withRNCloudStorageIos.js.map +1 -0
- package/lib/commonjs/google-drive/index.js +150 -0
- package/lib/commonjs/google-drive/index.js.map +1 -0
- package/lib/commonjs/google-drive/types.js +2 -0
- package/lib/commonjs/google-drive/types.js.map +1 -0
- package/lib/commonjs/hooks/useCloudFile.js +39 -0
- package/lib/commonjs/hooks/useCloudFile.js.map +1 -0
- package/lib/commonjs/index.js +36 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/types/main.js +13 -0
- package/lib/commonjs/types/main.js.map +1 -0
- package/lib/commonjs/types/native.js +2 -0
- package/lib/commonjs/types/native.js.map +1 -0
- package/lib/module/RNCloudStorage.js +45 -0
- package/lib/module/RNCloudStorage.js.map +1 -0
- package/lib/module/createRNCloudStorage.js +20 -0
- package/lib/module/createRNCloudStorage.js.map +1 -0
- package/lib/module/expo-plugin/withRNCloudStorage.js +7 -0
- package/lib/module/expo-plugin/withRNCloudStorage.js.map +1 -0
- package/lib/module/expo-plugin/withRNCloudStorageIos.js +32 -0
- package/lib/module/expo-plugin/withRNCloudStorageIos.js.map +1 -0
- package/lib/module/google-drive/index.js +143 -0
- package/lib/module/google-drive/index.js.map +1 -0
- package/lib/module/google-drive/types.js +2 -0
- package/lib/module/google-drive/types.js.map +1 -0
- package/lib/module/hooks/useCloudFile.js +31 -0
- package/lib/module/hooks/useCloudFile.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/types/main.js +6 -0
- package/lib/module/types/main.js.map +1 -0
- package/lib/module/types/native.js +2 -0
- package/lib/module/types/native.js.map +1 -0
- package/lib/typescript/RNCloudStorage.d.ts +35 -0
- package/lib/typescript/RNCloudStorage.d.ts.map +1 -0
- package/lib/typescript/createRNCloudStorage.d.ts +3 -0
- package/lib/typescript/createRNCloudStorage.d.ts.map +1 -0
- package/lib/typescript/expo-plugin/withRNCloudStorage.d.ts +10 -0
- package/lib/typescript/expo-plugin/withRNCloudStorage.d.ts.map +1 -0
- package/lib/typescript/expo-plugin/withRNCloudStorageIos.d.ts +4 -0
- package/lib/typescript/expo-plugin/withRNCloudStorageIos.d.ts.map +1 -0
- package/lib/typescript/google-drive/index.d.ts +19 -0
- package/lib/typescript/google-drive/index.d.ts.map +1 -0
- package/lib/typescript/google-drive/types.d.ts +54 -0
- package/lib/typescript/google-drive/types.d.ts.map +1 -0
- package/lib/typescript/hooks/useCloudFile.d.ts +8 -0
- package/lib/typescript/hooks/useCloudFile.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +5 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/types/main.d.ts +5 -0
- package/lib/typescript/types/main.d.ts.map +1 -0
- package/lib/typescript/types/native.d.ts +8 -0
- package/lib/typescript/types/native.d.ts.map +1 -0
- package/package.json +186 -0
- package/react-native-cloud-storage.podspec +35 -0
- package/src/RNCloudStorage.ts +50 -0
- package/src/createRNCloudStorage.ts +31 -0
- package/src/expo-plugin/withRNCloudStorage.ts +15 -0
- package/src/expo-plugin/withRNCloudStorageIos.ts +44 -0
- package/src/google-drive/index.ts +163 -0
- package/src/google-drive/types.ts +61 -0
- package/src/hooks/useCloudFile.ts +40 -0
- package/src/index.ts +5 -0
- package/src/types/main.ts +4 -0
- package/src/types/native.ts +8 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _reactNativeGoogleDriveApiWrapperJs = require("react-native-google-drive-api-wrapper-js");
|
|
8
|
+
class GoogleDriveApiClient {
|
|
9
|
+
static drive = new _reactNativeGoogleDriveApiWrapperJs.GDrive();
|
|
10
|
+
constructor() {
|
|
11
|
+
GoogleDriveApiClient.drive.fetchTimeout = 3000;
|
|
12
|
+
return new Proxy(this, {
|
|
13
|
+
// before calling any function, check if the access token is set
|
|
14
|
+
get(target, prop) {
|
|
15
|
+
if (typeof target[prop] === 'function') {
|
|
16
|
+
if (!GoogleDriveApiClient.drive.accessToken) {
|
|
17
|
+
throw new Error(`Google Drive access token is not set, cannot call function ${prop.toString()}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return target[prop];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// when setting accessToken, set it on the GDrive instance
|
|
26
|
+
static set accessToken(accessToken) {
|
|
27
|
+
GoogleDriveApiClient.drive.accessToken = accessToken;
|
|
28
|
+
}
|
|
29
|
+
static get accessToken() {
|
|
30
|
+
return GoogleDriveApiClient.drive.accessToken;
|
|
31
|
+
}
|
|
32
|
+
getRootDirectory(scope) {
|
|
33
|
+
switch (scope) {
|
|
34
|
+
case 'documents':
|
|
35
|
+
return 'drive';
|
|
36
|
+
case 'hidden':
|
|
37
|
+
return 'appDataFolder';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
resolvePathToDirectories(path) {
|
|
41
|
+
if (path.startsWith('/')) path = path.slice(1);
|
|
42
|
+
if (path.endsWith('/')) path = path.slice(0, -1);
|
|
43
|
+
const directories = path.split('/');
|
|
44
|
+
const actualFilename = directories.pop() ?? '';
|
|
45
|
+
return {
|
|
46
|
+
directories,
|
|
47
|
+
filename: actualFilename
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
findParentDirectoryId(files, directoryTree) {
|
|
51
|
+
const possibleTopDirectories = files.filter(f => f.mimeType === _reactNativeGoogleDriveApiWrapperJs.MimeTypes.FOLDER).filter(f => f.name === directoryTree[0]);
|
|
52
|
+
let topDirectoryId;
|
|
53
|
+
if (possibleTopDirectories.length === 0) return null;else if (possibleTopDirectories.length === 1) {
|
|
54
|
+
topDirectoryId = possibleTopDirectories[0].id;
|
|
55
|
+
} else {
|
|
56
|
+
/* when multiple directories carry the same name, we need to check every one of them if their parent id exists in
|
|
57
|
+
the files array - if it does not, it means that the directory is a child of the root directory and the one we're
|
|
58
|
+
looking for */
|
|
59
|
+
for (const possibleTopDirectory of possibleTopDirectories) {
|
|
60
|
+
if (!files.find(f => f.id === possibleTopDirectory.parents[0] && f.mimeType === _reactNativeGoogleDriveApiWrapperJs.MimeTypes.FOLDER)) {
|
|
61
|
+
topDirectoryId = possibleTopDirectory.id;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (!topDirectoryId) {
|
|
67
|
+
throw new Error(`Could not find top directory with name ${directoryTree[0]}`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// now, we traverse the directories array and get the id of the last directory from the files array
|
|
71
|
+
let currentDirectoryId = topDirectoryId;
|
|
72
|
+
for (let i = 1; i < directoryTree.length; i++) {
|
|
73
|
+
const currentDirectory = files.find(f => f.id === currentDirectoryId);
|
|
74
|
+
if (!currentDirectory) throw new Error(`Could not find directory with id ${currentDirectoryId}`);
|
|
75
|
+
const nextDirectory = files.find(f => f.name === directoryTree[i] && f.parents[0] === currentDirectoryId);
|
|
76
|
+
if (!nextDirectory) throw new Error(`Could not find directory with name ${directoryTree[i]}`);
|
|
77
|
+
currentDirectoryId = nextDirectory.id;
|
|
78
|
+
}
|
|
79
|
+
return currentDirectoryId;
|
|
80
|
+
}
|
|
81
|
+
async listFiles(scope) {
|
|
82
|
+
const files = await GoogleDriveApiClient.drive.files.list({
|
|
83
|
+
spaces: [this.getRootDirectory(scope)],
|
|
84
|
+
fields: 'files(id,kind,mimeType,name,parents,spaces)'
|
|
85
|
+
});
|
|
86
|
+
return files.files;
|
|
87
|
+
}
|
|
88
|
+
async getFileId(path, scope) {
|
|
89
|
+
const files = await this.listFiles(scope);
|
|
90
|
+
const {
|
|
91
|
+
directories,
|
|
92
|
+
filename
|
|
93
|
+
} = this.resolvePathToDirectories(path);
|
|
94
|
+
const parentDirectoryId = this.findParentDirectoryId(files, directories);
|
|
95
|
+
let file;
|
|
96
|
+
if (parentDirectoryId === null) {
|
|
97
|
+
/* when the file is supposes to be in the root directory, we need to get the file where the name is the filename
|
|
98
|
+
and the first parent has an id which does not exist in the files array */
|
|
99
|
+
file = files.find(f => f.name === filename && !files.find(f2 => f2.id === f.parents[0]));
|
|
100
|
+
} else {
|
|
101
|
+
file = files.find(f => f.name === filename && f.parents[0] === parentDirectoryId);
|
|
102
|
+
}
|
|
103
|
+
if (!file) throw new Error(`File not found`);
|
|
104
|
+
return file.id;
|
|
105
|
+
}
|
|
106
|
+
async fileExists(path, scope) {
|
|
107
|
+
try {
|
|
108
|
+
await this.getFileId(path, scope);
|
|
109
|
+
return true;
|
|
110
|
+
} catch (e) {
|
|
111
|
+
if (e.message === 'File not found') return false;else throw e;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async createFile(path, data, scope, overwrite) {
|
|
115
|
+
let fileId;
|
|
116
|
+
if (overwrite) {
|
|
117
|
+
try {
|
|
118
|
+
fileId = await this.getFileId(path, scope);
|
|
119
|
+
} catch (e) {
|
|
120
|
+
/* do nothing, simply create the file */
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const uploader = GoogleDriveApiClient.drive.files.newMultipartUploader().setData(data, _reactNativeGoogleDriveApiWrapperJs.MimeTypes.TEXT);
|
|
124
|
+
if (fileId) uploader.setIdOfFileToUpdate(fileId);else {
|
|
125
|
+
const files = await this.listFiles(scope);
|
|
126
|
+
const {
|
|
127
|
+
directories,
|
|
128
|
+
filename
|
|
129
|
+
} = this.resolvePathToDirectories(path);
|
|
130
|
+
const parentDirectoryId = this.findParentDirectoryId(files, directories);
|
|
131
|
+
uploader.setRequestBody({
|
|
132
|
+
name: filename,
|
|
133
|
+
parents: parentDirectoryId ? [parentDirectoryId] : scope === 'hidden' ? [this.getRootDirectory(scope)] : undefined
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
await uploader.execute();
|
|
137
|
+
}
|
|
138
|
+
async readFile(path, scope) {
|
|
139
|
+
const fileId = await this.getFileId(path, scope);
|
|
140
|
+
const content = await GoogleDriveApiClient.drive.files.getText(fileId);
|
|
141
|
+
return content;
|
|
142
|
+
}
|
|
143
|
+
async deleteFile(path, scope) {
|
|
144
|
+
const fileId = await this.getFileId(path, scope);
|
|
145
|
+
await GoogleDriveApiClient.drive.files.delete(fileId);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
var _default = GoogleDriveApiClient;
|
|
149
|
+
exports.default = _default;
|
|
150
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNativeGoogleDriveApiWrapperJs","require","GoogleDriveApiClient","drive","GDrive","constructor","fetchTimeout","Proxy","get","target","prop","accessToken","Error","toString","getRootDirectory","scope","resolvePathToDirectories","path","startsWith","slice","endsWith","directories","split","actualFilename","pop","filename","findParentDirectoryId","files","directoryTree","possibleTopDirectories","filter","f","mimeType","MimeTypes","FOLDER","name","topDirectoryId","length","id","possibleTopDirectory","find","parents","currentDirectoryId","i","currentDirectory","nextDirectory","listFiles","list","spaces","fields","getFileId","parentDirectoryId","file","f2","fileExists","e","message","createFile","data","overwrite","fileId","uploader","newMultipartUploader","setData","TEXT","setIdOfFileToUpdate","setRequestBody","undefined","execute","readFile","content","getText","deleteFile","delete","_default","exports","default"],"sourceRoot":"../../../src","sources":["google-drive/index.ts"],"mappings":";;;;;;AAAA,IAAAA,mCAAA,GAAAC,OAAA;AAKA,MAAMC,oBAAoB,CAAiC;EACzD,OAAeC,KAAK,GAAW,IAAIC,0CAAM,EAAE;EAE3CC,WAAWA,CAAA,EAAG;IACZH,oBAAoB,CAACC,KAAK,CAACG,YAAY,GAAG,IAAI;IAC9C,OAAO,IAAIC,KAAK,CAAC,IAAI,EAAE;MACrB;MACAC,GAAGA,CAACC,MAA4B,EAAEC,IAAgC,EAAE;QAClE,IAAI,OAAOD,MAAM,CAACC,IAAI,CAAC,KAAK,UAAU,EAAE;UACtC,IAAI,CAACR,oBAAoB,CAACC,KAAK,CAACQ,WAAW,EAAE;YAC3C,MAAM,IAAIC,KAAK,CAAE,8DAA6DF,IAAI,CAACG,QAAQ,EAAG,EAAC,CAAC;UAClG;QACF;QAEA,OAAOJ,MAAM,CAACC,IAAI,CAAC;MACrB;IACF,CAAC,CAAC;EACJ;;EAEA;EACA,WAAkBC,WAAWA,CAACA,WAAmB,EAAE;IACjDT,oBAAoB,CAACC,KAAK,CAACQ,WAAW,GAAGA,WAAW;EACtD;EAEA,WAAkBA,WAAWA,CAAA,EAAW;IACtC,OAAOT,oBAAoB,CAACC,KAAK,CAACQ,WAAW;EAC/C;EAEQG,gBAAgBA,CAACC,KAAgC,EAA6B;IACpF,QAAQA,KAAK;MACX,KAAK,WAAW;QACd,OAAO,OAAO;MAChB,KAAK,QAAQ;QACX,OAAO,eAAe;IAAC;EAE7B;EAEQC,wBAAwBA,CAACC,IAAY,EAA+C;IAC1F,IAAIA,IAAI,CAACC,UAAU,CAAC,GAAG,CAAC,EAAED,IAAI,GAAGA,IAAI,CAACE,KAAK,CAAC,CAAC,CAAC;IAC9C,IAAIF,IAAI,CAACG,QAAQ,CAAC,G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@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["google-drive/types.ts"],"mappings":""}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useCloudFile = void 0;
|
|
7
|
+
var _RNCloudStorage = _interopRequireDefault(require("../RNCloudStorage"));
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
const useCloudFile = (path, scope) => {
|
|
11
|
+
const [content, setContent] = (0, _react.useState)(null);
|
|
12
|
+
const read = (0, _react.useCallback)(async () => {
|
|
13
|
+
const exists = await _RNCloudStorage.default.exists(path, scope);
|
|
14
|
+
if (!exists) {
|
|
15
|
+
setContent(null);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
_RNCloudStorage.default.readFile(path, scope).then(setContent);
|
|
19
|
+
}, [path, scope]);
|
|
20
|
+
(0, _react.useEffect)(() => {
|
|
21
|
+
read();
|
|
22
|
+
}, [read]);
|
|
23
|
+
const update = (0, _react.useCallback)(async newContent => {
|
|
24
|
+
await _RNCloudStorage.default.writeFile(path, newContent, scope);
|
|
25
|
+
read();
|
|
26
|
+
}, [path, scope, read]);
|
|
27
|
+
const remove = (0, _react.useCallback)(async () => {
|
|
28
|
+
await _RNCloudStorage.default.unlink(path, scope);
|
|
29
|
+
setContent(null);
|
|
30
|
+
}, [path, scope]);
|
|
31
|
+
return {
|
|
32
|
+
content,
|
|
33
|
+
read,
|
|
34
|
+
update,
|
|
35
|
+
remove
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
exports.useCloudFile = useCloudFile;
|
|
39
|
+
//# sourceMappingURL=useCloudFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_RNCloudStorage","_interopRequireDefault","require","_react","obj","__esModule","default","useCloudFile","path","scope","content","setContent","useState","read","useCallback","exists","RNCloudStorage","readFile","then","useEffect","update","newContent","writeFile","remove","unlink","exports"],"sourceRoot":"../../../src","sources":["hooks/useCloudFile.ts"],"mappings":";;;;;;AACA,IAAAA,eAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAAyD,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAElD,MAAMG,YAAY,GAAGA,CAACC,IAAY,EAAEC,KAAmB,KAAK;EACjE,MAAM,CAACC,OAAO,EAAEC,UAAU,CAAC,GAAG,IAAAC,eAAQ,EAAgB,IAAI,CAAC;EAE3D,MAAMC,IAAI,GAAG,IAAAC,kBAAW,EAAC,YAAY;IACnC,MAAMC,MAAM,GAAG,MAAMC,uBAAc,CAACD,MAAM,CAACP,IAAI,EAAEC,KAAK,CAAC;IACvD,IAAI,CAACM,MAAM,EAAE;MACXJ,UAAU,CAAC,IAAI,CAAC;MAChB;IACF;IACAK,uBAAc,CAACC,QAAQ,CAACT,IAAI,EAAEC,KAAK,CAAC,CAACS,IAAI,CAACP,UAAU,CAAC;EACvD,CAAC,EAAE,CAACH,IAAI,EAAEC,KAAK,CAAC,CAAC;EAEjB,IAAAU,gBAAS,EAAC,MAAM;IACdN,IAAI,EAAE;EACR,CAAC,EAAE,CAACA,IAAI,CAAC,CAAC;EAEV,MAAMO,MAAM,GAAG,IAAAN,kBAAW,EACxB,MAAOO,UAAkB,IAAK;IAC5B,MAAML,uBAAc,CAACM,SAAS,CAACd,IAAI,EAAEa,UAAU,EAAEZ,KAAK,CAAC;IACvDI,IAAI,EAAE;EACR,CAAC,EACD,CAACL,IAAI,EAAEC,KAAK,EAAEI,IAAI,CAAC,CACpB;EAED,MAAMU,MAAM,GAAG,IAAAT,kBAAW,EAAC,YAAY;IACrC,MAAME,uBAAc,CAACQ,MAAM,CAAChB,IAAI,EAAEC,KAAK,CAAC;IACxCE,UAAU,CAAC,IAAI,CAAC;EAClB,CAAC,EAAE,CAACH,IAAI,EAAEC,KAAK,CAAC,CAAC;EAEjB,OAAO;IACLC,OAAO;IACPG,IAAI;IACJO,MAAM;IACNG;EACF,CAAC;AACH,CAAC;AAACE,OAAA,CAAAlB,YAAA,GAAAA,YAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {};
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _RNCloudStorage = _interopRequireDefault(require("./RNCloudStorage"));
|
|
9
|
+
var _main = require("./types/main");
|
|
10
|
+
Object.keys(_main).forEach(function (key) {
|
|
11
|
+
if (key === "default" || key === "__esModule") return;
|
|
12
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
13
|
+
if (key in exports && exports[key] === _main[key]) return;
|
|
14
|
+
Object.defineProperty(exports, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () {
|
|
17
|
+
return _main[key];
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
var _useCloudFile = require("./hooks/useCloudFile");
|
|
22
|
+
Object.keys(_useCloudFile).forEach(function (key) {
|
|
23
|
+
if (key === "default" || key === "__esModule") return;
|
|
24
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
25
|
+
if (key in exports && exports[key] === _useCloudFile[key]) return;
|
|
26
|
+
Object.defineProperty(exports, key, {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function () {
|
|
29
|
+
return _useCloudFile[key];
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
34
|
+
var _default = _RNCloudStorage.default;
|
|
35
|
+
exports.default = _default;
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_RNCloudStorage","_interopRequireDefault","require","_main","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_useCloudFile","obj","__esModule","default","_default","RNCloudStorage"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;AAAA,IAAAA,eAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAF,KAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,KAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,KAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,aAAA,GAAAd,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAW,aAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAS,aAAA,CAAAT,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,aAAA,CAAAT,GAAA;IAAA;EAAA;AAAA;AAAqC,SAAAN,uBAAAgB,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,IAAAG,QAAA,GAEtBC,uBAAc;AAAAT,OAAA,CAAAO,OAAA,GAAAC,QAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.StorageScope = void 0;
|
|
7
|
+
let StorageScope = /*#__PURE__*/function (StorageScope) {
|
|
8
|
+
StorageScope["Documents"] = "documents";
|
|
9
|
+
StorageScope["Hidden"] = "hidden";
|
|
10
|
+
return StorageScope;
|
|
11
|
+
}({});
|
|
12
|
+
exports.StorageScope = StorageScope;
|
|
13
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["StorageScope","exports"],"sourceRoot":"../../../src","sources":["types/main.ts"],"mappings":";;;;;;IAAYA,YAAY,0BAAZA,YAAY;EAAZA,YAAY;EAAZA,YAAY;EAAA,OAAZA,YAAY;AAAA;AAAAC,OAAA,CAAAD,YAAA,GAAAA,YAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/native.ts"],"mappings":""}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import createRNCloudStorage from './createRNCloudStorage';
|
|
2
|
+
import GoogleDriveApiClient from './google-drive';
|
|
3
|
+
const nativeInstance = createRNCloudStorage();
|
|
4
|
+
const RNCloudStorage = {
|
|
5
|
+
setGoogleDriveAccessToken: accessToken => GoogleDriveApiClient.accessToken = accessToken,
|
|
6
|
+
/**
|
|
7
|
+
* Tests whether or not the file at the given path exists.
|
|
8
|
+
* @param path The path to test.
|
|
9
|
+
* @param scope The directory scope the path is in.
|
|
10
|
+
* @returns A promise that resolves to true if the path exists, false otherwise.
|
|
11
|
+
*/
|
|
12
|
+
exists: (path, scope) => {
|
|
13
|
+
return nativeInstance.fileExists(path, scope);
|
|
14
|
+
},
|
|
15
|
+
/**
|
|
16
|
+
* Writes to the file at the given path, creating it if it doesn't exist or overwriting it if it does.
|
|
17
|
+
* @param path The file to write to.
|
|
18
|
+
* @param data The data to write.
|
|
19
|
+
* @param scope The directory scope the path is in.
|
|
20
|
+
* @returns A promise that resolves when the file has been written.
|
|
21
|
+
*/
|
|
22
|
+
writeFile: (path, data, scope) => {
|
|
23
|
+
return nativeInstance.createFile(path, data, scope, true);
|
|
24
|
+
},
|
|
25
|
+
/**
|
|
26
|
+
* Reads the contents of the file at the given path.
|
|
27
|
+
* @param path The file to read.
|
|
28
|
+
* @param scope The directory scope the path is in.
|
|
29
|
+
* @returns A promise that resolves to the contents of the file.
|
|
30
|
+
*/
|
|
31
|
+
readFile: (path, scope) => {
|
|
32
|
+
return nativeInstance.readFile(path, scope);
|
|
33
|
+
},
|
|
34
|
+
/**
|
|
35
|
+
* Deletes the file at the given path.
|
|
36
|
+
* @param path The file to delete.
|
|
37
|
+
* @param scope The directory scope the path is in.
|
|
38
|
+
* @returns A promise that resolves when the file has been deleted.
|
|
39
|
+
*/
|
|
40
|
+
unlink: (path, scope) => {
|
|
41
|
+
return nativeInstance.deleteFile(path, scope);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
export default RNCloudStorage;
|
|
45
|
+
//# sourceMappingURL=RNCloudStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createRNCloudStorage","GoogleDriveApiClient","nativeInstance","RNCloudStorage","setGoogleDriveAccessToken","accessToken","exists","path","scope","fileExists","writeFile","data","createFile","readFile","unlink","deleteFile"],"sourceRoot":"../../src","sources":["RNCloudStorage.ts"],"mappings":"AAAA,OAAOA,oBAAoB,MAAM,wBAAwB;AACzD,OAAOC,oBAAoB,MAAM,gBAAgB;AAGjD,MAAMC,cAAc,GAAGF,oBAAoB,EAAE;AAC7C,MAAMG,cAAc,GAAG;EACrBC,yBAAyB,EAAGC,WAAmB,IAAMJ,oBAAoB,CAACI,WAAW,GAAGA,WAAY;EACpG;AACF;AACA;AACA;AACA;AACA;EACEC,MAAM,EAAEA,CAACC,IAAY,EAAEC,KAAmB,KAAuB;IAC/D,OAAON,cAAc,CAACO,UAAU,CAACF,IAAI,EAAEC,KAAK,CAAC;EAC/C,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;AACA;EACEE,SAAS,EAAEA,CAACH,IAAY,EAAEI,IAAY,EAAEH,KAAmB,KAAoB;IAC7E,OAAON,cAAc,CAACU,UAAU,CAACL,IAAI,EAAEI,IAAI,EAAEH,KAAK,EAAE,IAAI,CAAC;EAC3D,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;EACEK,QAAQ,EAAEA,CAACN,IAAY,EAAEC,KAAmB,KAAsB;IAChE,OAAON,cAAc,CAACW,QAAQ,CAACN,IAAI,EAAEC,KAAK,CAAC;EAC7C,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;EACEM,MAAM,EAAEA,CAACP,IAAY,EAAEC,KAAmB,KAAoB;IAC5D,OAAON,cAAc,CAACa,UAAU,CAACR,IAAI,EAAEC,KAAK,CAAC;EAC/C;AACF,CAAC;AAED,eAAeL,cAAc"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { NativeModules, Platform } from 'react-native';
|
|
2
|
+
import GoogleDriveApiClient from './google-drive';
|
|
3
|
+
const LINKING_ERROR = `The package 'react-native-cloud-storage' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
|
|
4
|
+
ios: "- You have run 'pod install'\n",
|
|
5
|
+
default: ''
|
|
6
|
+
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
|
|
7
|
+
export default function createRNCloudStorage() {
|
|
8
|
+
if (Platform.OS === 'ios') {
|
|
9
|
+
return NativeModules.CloudStorage ?? new Proxy({}, {
|
|
10
|
+
get() {
|
|
11
|
+
throw new Error(LINKING_ERROR);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
if (Platform.OS === 'android') {
|
|
16
|
+
return new GoogleDriveApiClient();
|
|
17
|
+
}
|
|
18
|
+
throw new Error('Unsupported platform');
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=createRNCloudStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NativeModules","Platform","GoogleDriveApiClient","LINKING_ERROR","select","ios","default","createRNCloudStorage","OS","CloudStorage","Proxy","get","Error"],"sourceRoot":"../../src","sources":["createRNCloudStorage.ts"],"mappings":"AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAEtD,OAAOC,oBAAoB,MAAM,gBAAgB;AAEjD,MAAMC,aAAa,GAChB,qFAAoF,GACrFF,QAAQ,CAACG,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,eAAe,SAASC,oBAAoBA,CAAA,EAAyB;EACnE,IAAIN,QAAQ,CAACO,EAAE,KAAK,KAAK,EAAE;IACzB,OACGR,aAAa,CAACS,YAAY,IAC3B,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;MACEC,GAAGA,CAAA,EAAG;QACJ,MAAM,IAAIC,KAAK,CAACT,aAAa,CAAC;MAChC;IACF,CAAC,CACF;EAEL;EAEA,IAAIF,QAAQ,CAACO,EAAE,KAAK,SAAS,EAAE;IAC7B,OAAO,IAAIN,oBAAoB,EAAE;EACnC;EAEA,MAAM,IAAIU,KAAK,CAAC,sBAAsB,CAAC;AACzC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import withRNCloudStorageIos from './withRNCloudStorageIos';
|
|
2
|
+
|
|
3
|
+
// Android config plugin not needed as there's no native code to configure.
|
|
4
|
+
|
|
5
|
+
const withRNCloudStorage = (config, options) => withRNCloudStorageIos(config, (options === null || options === void 0 ? void 0 : options.iCloudContainerEnvironment) ?? 'Production');
|
|
6
|
+
export default withRNCloudStorage;
|
|
7
|
+
//# sourceMappingURL=withRNCloudStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["withRNCloudStorageIos","withRNCloudStorage","config","options","iCloudContainerEnvironment"],"sourceRoot":"../../../src","sources":["expo-plugin/withRNCloudStorage.ts"],"mappings":"AAAA,OAAOA,qBAAqB,MAAM,yBAAyB;;AAG3D;;AAQA,MAAMC,kBAAmE,GAAGA,CAACC,MAAM,EAAEC,OAAO,KAC1FH,qBAAqB,CAACE,MAAM,EAAE,CAAAC,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEC,0BAA0B,KAAI,YAAY,CAAC;AAEpF,eAAeH,kBAAkB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { withEntitlementsPlist, withInfoPlist, withPlugins } from '@expo/config-plugins';
|
|
2
|
+
const withRNCloudStorageInfoPlist = config => withInfoPlist(config, async newConfig => {
|
|
3
|
+
var _config$ios;
|
|
4
|
+
if (!((_config$ios = config.ios) !== null && _config$ios !== void 0 && _config$ios.bundleIdentifier)) {
|
|
5
|
+
throw new Error('Missing iOS bundle identifier');
|
|
6
|
+
}
|
|
7
|
+
const infoPlist = newConfig.modResults;
|
|
8
|
+
infoPlist.NSUbiquitousContainers = {
|
|
9
|
+
[`iCloud.${config.ios.bundleIdentifier}`]: {
|
|
10
|
+
NSUbiquitousContainerIsDocumentScopePublic: true,
|
|
11
|
+
NSUbiquitousContainerSupportedFolderLevels: 'Any',
|
|
12
|
+
NSUbiquitousContainerName: config.slug
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
return newConfig;
|
|
16
|
+
});
|
|
17
|
+
const withRNCloudStorageEntitlementsPlist = (config, iCloudContainerEnvironment) => withEntitlementsPlist(config, async newConfig => {
|
|
18
|
+
var _config$ios2;
|
|
19
|
+
if (!((_config$ios2 = config.ios) !== null && _config$ios2 !== void 0 && _config$ios2.bundleIdentifier)) {
|
|
20
|
+
throw new Error('Missing iOS bundle identifier');
|
|
21
|
+
}
|
|
22
|
+
const entitlementsPlist = newConfig.modResults;
|
|
23
|
+
entitlementsPlist['com.apple.developer.icloud-container-identifiers'] = [`iCloud.${config.ios.bundleIdentifier}`];
|
|
24
|
+
entitlementsPlist['com.apple.developer.icloud-services'] = ['CloudDocuments'];
|
|
25
|
+
entitlementsPlist['com.apple.developer.icloud-container-environment'] = iCloudContainerEnvironment;
|
|
26
|
+
entitlementsPlist['com.apple.developer.ubiquity-container-identifiers'] = [`iCloud.${config.ios.bundleIdentifier}`];
|
|
27
|
+
entitlementsPlist['com.apple.developer.ubiquity-kvstore-identifier'] = `$(TeamIdentifierPrefix)${config.ios.bundleIdentifier}`;
|
|
28
|
+
return newConfig;
|
|
29
|
+
});
|
|
30
|
+
const withRNCloudStorageIos = (config, iCloudContainerEnvironment) => withPlugins(config, [withRNCloudStorageInfoPlist, [withRNCloudStorageEntitlementsPlist, iCloudContainerEnvironment]]);
|
|
31
|
+
export default withRNCloudStorageIos;
|
|
32
|
+
//# sourceMappingURL=withRNCloudStorageIos.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["withEntitlementsPlist","withInfoPlist","withPlugins","withRNCloudStorageInfoPlist","config","newConfig","_config$ios","ios","bundleIdentifier","Error","infoPlist","modResults","NSUbiquitousContainers","NSUbiquitousContainerIsDocumentScopePublic","NSUbiquitousContainerSupportedFolderLevels","NSUbiquitousContainerName","slug","withRNCloudStorageEntitlementsPlist","iCloudContainerEnvironment","_config$ios2","entitlementsPlist","withRNCloudStorageIos"],"sourceRoot":"../../../src","sources":["expo-plugin/withRNCloudStorageIos.ts"],"mappings":"AAAA,SAASA,qBAAqB,EAAEC,aAAa,EAAEC,WAAW,QAAQ,sBAAsB;AAGxF,MAAMC,2BAA2B,GAAIC,MAAkB,IACrDH,aAAa,CAACG,MAAM,EA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AAClB,CAAC,CAAC;AAEJ,MAAMgB,qBAAqB,GAAGA,CAACjB,MAAkB,EAAEc,0BAAwD,KACzGhB,WAAW,CAACE,MAAM,EAAE,CAACD,2BAA2B,EAAE,CAACc,mCAAmC,EAAEC,0BAA0B,CAAC,CAAC,CAAC;AAEvH,eAAeG,qBAAqB"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { GDrive, MimeTypes } from 'react-native-google-drive-api-wrapper-js';
|
|
2
|
+
class GoogleDriveApiClient {
|
|
3
|
+
static drive = new GDrive();
|
|
4
|
+
constructor() {
|
|
5
|
+
GoogleDriveApiClient.drive.fetchTimeout = 3000;
|
|
6
|
+
return new Proxy(this, {
|
|
7
|
+
// before calling any function, check if the access token is set
|
|
8
|
+
get(target, prop) {
|
|
9
|
+
if (typeof target[prop] === 'function') {
|
|
10
|
+
if (!GoogleDriveApiClient.drive.accessToken) {
|
|
11
|
+
throw new Error(`Google Drive access token is not set, cannot call function ${prop.toString()}`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return target[prop];
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// when setting accessToken, set it on the GDrive instance
|
|
20
|
+
static set accessToken(accessToken) {
|
|
21
|
+
GoogleDriveApiClient.drive.accessToken = accessToken;
|
|
22
|
+
}
|
|
23
|
+
static get accessToken() {
|
|
24
|
+
return GoogleDriveApiClient.drive.accessToken;
|
|
25
|
+
}
|
|
26
|
+
getRootDirectory(scope) {
|
|
27
|
+
switch (scope) {
|
|
28
|
+
case 'documents':
|
|
29
|
+
return 'drive';
|
|
30
|
+
case 'hidden':
|
|
31
|
+
return 'appDataFolder';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
resolvePathToDirectories(path) {
|
|
35
|
+
if (path.startsWith('/')) path = path.slice(1);
|
|
36
|
+
if (path.endsWith('/')) path = path.slice(0, -1);
|
|
37
|
+
const directories = path.split('/');
|
|
38
|
+
const actualFilename = directories.pop() ?? '';
|
|
39
|
+
return {
|
|
40
|
+
directories,
|
|
41
|
+
filename: actualFilename
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
findParentDirectoryId(files, directoryTree) {
|
|
45
|
+
const possibleTopDirectories = files.filter(f => f.mimeType === MimeTypes.FOLDER).filter(f => f.name === directoryTree[0]);
|
|
46
|
+
let topDirectoryId;
|
|
47
|
+
if (possibleTopDirectories.length === 0) return null;else if (possibleTopDirectories.length === 1) {
|
|
48
|
+
topDirectoryId = possibleTopDirectories[0].id;
|
|
49
|
+
} else {
|
|
50
|
+
/* when multiple directories carry the same name, we need to check every one of them if their parent id exists in
|
|
51
|
+
the files array - if it does not, it means that the directory is a child of the root directory and the one we're
|
|
52
|
+
looking for */
|
|
53
|
+
for (const possibleTopDirectory of possibleTopDirectories) {
|
|
54
|
+
if (!files.find(f => f.id === possibleTopDirectory.parents[0] && f.mimeType === MimeTypes.FOLDER)) {
|
|
55
|
+
topDirectoryId = possibleTopDirectory.id;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (!topDirectoryId) {
|
|
61
|
+
throw new Error(`Could not find top directory with name ${directoryTree[0]}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// now, we traverse the directories array and get the id of the last directory from the files array
|
|
65
|
+
let currentDirectoryId = topDirectoryId;
|
|
66
|
+
for (let i = 1; i < directoryTree.length; i++) {
|
|
67
|
+
const currentDirectory = files.find(f => f.id === currentDirectoryId);
|
|
68
|
+
if (!currentDirectory) throw new Error(`Could not find directory with id ${currentDirectoryId}`);
|
|
69
|
+
const nextDirectory = files.find(f => f.name === directoryTree[i] && f.parents[0] === currentDirectoryId);
|
|
70
|
+
if (!nextDirectory) throw new Error(`Could not find directory with name ${directoryTree[i]}`);
|
|
71
|
+
currentDirectoryId = nextDirectory.id;
|
|
72
|
+
}
|
|
73
|
+
return currentDirectoryId;
|
|
74
|
+
}
|
|
75
|
+
async listFiles(scope) {
|
|
76
|
+
const files = await GoogleDriveApiClient.drive.files.list({
|
|
77
|
+
spaces: [this.getRootDirectory(scope)],
|
|
78
|
+
fields: 'files(id,kind,mimeType,name,parents,spaces)'
|
|
79
|
+
});
|
|
80
|
+
return files.files;
|
|
81
|
+
}
|
|
82
|
+
async getFileId(path, scope) {
|
|
83
|
+
const files = await this.listFiles(scope);
|
|
84
|
+
const {
|
|
85
|
+
directories,
|
|
86
|
+
filename
|
|
87
|
+
} = this.resolvePathToDirectories(path);
|
|
88
|
+
const parentDirectoryId = this.findParentDirectoryId(files, directories);
|
|
89
|
+
let file;
|
|
90
|
+
if (parentDirectoryId === null) {
|
|
91
|
+
/* when the file is supposes to be in the root directory, we need to get the file where the name is the filename
|
|
92
|
+
and the first parent has an id which does not exist in the files array */
|
|
93
|
+
file = files.find(f => f.name === filename && !files.find(f2 => f2.id === f.parents[0]));
|
|
94
|
+
} else {
|
|
95
|
+
file = files.find(f => f.name === filename && f.parents[0] === parentDirectoryId);
|
|
96
|
+
}
|
|
97
|
+
if (!file) throw new Error(`File not found`);
|
|
98
|
+
return file.id;
|
|
99
|
+
}
|
|
100
|
+
async fileExists(path, scope) {
|
|
101
|
+
try {
|
|
102
|
+
await this.getFileId(path, scope);
|
|
103
|
+
return true;
|
|
104
|
+
} catch (e) {
|
|
105
|
+
if (e.message === 'File not found') return false;else throw e;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async createFile(path, data, scope, overwrite) {
|
|
109
|
+
let fileId;
|
|
110
|
+
if (overwrite) {
|
|
111
|
+
try {
|
|
112
|
+
fileId = await this.getFileId(path, scope);
|
|
113
|
+
} catch (e) {
|
|
114
|
+
/* do nothing, simply create the file */
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const uploader = GoogleDriveApiClient.drive.files.newMultipartUploader().setData(data, MimeTypes.TEXT);
|
|
118
|
+
if (fileId) uploader.setIdOfFileToUpdate(fileId);else {
|
|
119
|
+
const files = await this.listFiles(scope);
|
|
120
|
+
const {
|
|
121
|
+
directories,
|
|
122
|
+
filename
|
|
123
|
+
} = this.resolvePathToDirectories(path);
|
|
124
|
+
const parentDirectoryId = this.findParentDirectoryId(files, directories);
|
|
125
|
+
uploader.setRequestBody({
|
|
126
|
+
name: filename,
|
|
127
|
+
parents: parentDirectoryId ? [parentDirectoryId] : scope === 'hidden' ? [this.getRootDirectory(scope)] : undefined
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
await uploader.execute();
|
|
131
|
+
}
|
|
132
|
+
async readFile(path, scope) {
|
|
133
|
+
const fileId = await this.getFileId(path, scope);
|
|
134
|
+
const content = await GoogleDriveApiClient.drive.files.getText(fileId);
|
|
135
|
+
return content;
|
|
136
|
+
}
|
|
137
|
+
async deleteFile(path, scope) {
|
|
138
|
+
const fileId = await this.getFileId(path, scope);
|
|
139
|
+
await GoogleDriveApiClient.drive.files.delete(fileId);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
export default GoogleDriveApiClient;
|
|
143
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["GDrive","MimeTypes","GoogleDriveApiClient","drive","constructor","fetchTimeout","Proxy","get","target","prop","accessToken","Error","toString","getRootDirectory","scope","resolvePathToDirectories","path","startsWith","slice","endsWith","directories","split","actualFilename","pop","filename","findParentDirectoryId","files","directoryTree","possibleTopDirectories","filter","f","mimeType","FOLDER","name","topDirectoryId","length","id","possibleTopDirectory","find","parents","currentDirectoryId","i","currentDirectory","nextDirectory","listFiles","list","spaces","fields","getFileId","parentDirectoryId","file","f2","fileExists","e","message","createFile","data","overwrite","fileId","uploader","newMultipartUploader","setData","TEXT","setIdOfFileToUpdate","setRequestBody","undefined","execute","readFile","content","getText","deleteFile","delete"],"sourceRoot":"../../../src","sources":["google-drive/index.ts"],"mappings":"AAAA,SAASA,MAAM,EAAEC,SAAS,QAAQ,0CAA0C;AAK5E,MAAMC,o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zC,MAAM;QAAEM,WAAW;QAAEI;MAAS,CAAC,GAAG,IAAI,CAACT,wBAAwB,CAACC,IAAI,CAAC;MACrE,MAAMiC,iBAAiB,GAAG,IAAI,CAACxB,qBAAqB,CAACC,KAAK,EAAEN,WAAW,CAAC;MACxEuC,QAAQ,CAACK,cAAc,CAAC;QACtB/B,IAAI,EAAET,QAAQ;QACde,OAAO,EAAEU,iBAAiB,GACtB,CAACA,iBAAiB,CAAC,GACnBnC,KAAK,KAAK,QAAQ,GAClB,CAAC,IAAI,CAACD,gBAAgB,CAACC,KAAK,CAAC,CAAC,GAC9BmD;MACN,CAAC,CAAC;IACJ;IACA,MAAMN,QAAQ,CAACO,OAAO,EAAE;EAC1B;EAEA,MAAMC,QAAQA,CAACnD,IAAY,EAAEF,KAAgC,EAAmB;IAC9E,MAAM4C,MAAM,GAAG,MAAM,IAAI,CAACV,SAAS,CAAChC,IAAI,EAAEF,KAAK,CAAC;IAChD,MAAMsD,OAAO,GAAG,MAAMlE,oBAAoB,CAACC,KAAK,CAACuB,KAAK,CAAC2C,OAAO,CAACX,MAAM,CAAC;IACtE,OAAOU,OAAO;EAChB;EAEA,MAAME,UAAUA,CAACtD,IAAY,EAAEF,KAAgC,EAAiB;IAC9E,MAAM4C,MAAM,GAAG,MAAM,IAAI,CAACV,SAAS,CAAChC,IAAI,EAAEF,KAAK,CAAC;IAChD,MAAMZ,oBAAoB,CAACC,KAAK,CAACuB,KAAK,CAAC6C,MAAM,CAACb,MAAM,CAAC;EACvD;AACF;AAEA,eAAexD,oBAAoB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["google-drive/types.ts"],"mappings":""}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import RNCloudStorage from '../RNCloudStorage';
|
|
2
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
3
|
+
export const useCloudFile = (path, scope) => {
|
|
4
|
+
const [content, setContent] = useState(null);
|
|
5
|
+
const read = useCallback(async () => {
|
|
6
|
+
const exists = await RNCloudStorage.exists(path, scope);
|
|
7
|
+
if (!exists) {
|
|
8
|
+
setContent(null);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
RNCloudStorage.readFile(path, scope).then(setContent);
|
|
12
|
+
}, [path, scope]);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
read();
|
|
15
|
+
}, [read]);
|
|
16
|
+
const update = useCallback(async newContent => {
|
|
17
|
+
await RNCloudStorage.writeFile(path, newContent, scope);
|
|
18
|
+
read();
|
|
19
|
+
}, [path, scope, read]);
|
|
20
|
+
const remove = useCallback(async () => {
|
|
21
|
+
await RNCloudStorage.unlink(path, scope);
|
|
22
|
+
setContent(null);
|
|
23
|
+
}, [path, scope]);
|
|
24
|
+
return {
|
|
25
|
+
content,
|
|
26
|
+
read,
|
|
27
|
+
update,
|
|
28
|
+
remove
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=useCloudFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["RNCloudStorage","useCallback","useEffect","useState","useCloudFile","path","scope","content","setContent","read","exists","readFile","then","update","newContent","writeFile","remove","unlink"],"sourceRoot":"../../../src","sources":["hooks/useCloudFile.ts"],"mappings":"AACA,OAAOA,cAAc,MAAM,mBAAmB;AAC9C,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAExD,OAAO,MAAMC,YAAY,GAAGA,CAACC,IAAY,EAAEC,KAAmB,KAAK;EACjE,MAAM,CAACC,OAAO,EAAEC,UAAU,CAAC,GAAGL,QAAQ,CAAgB,IAAI,CAAC;EAE3D,MAAMM,IAAI,GAAGR,WAAW,CAAC,YAAY;IACnC,MAAMS,MAAM,GAAG,MAAMV,cAAc,CAACU,MAAM,CAACL,IAAI,EAAEC,KAAK,CAAC;IACvD,IAAI,CAACI,MAAM,EAAE;MACXF,UAAU,CAAC,IAAI,CAAC;MAChB;IACF;IACAR,cAAc,CAACW,QAAQ,CAACN,IAAI,EAAEC,KAAK,CAAC,CAACM,IAAI,CAACJ,UAAU,CAAC;EACvD,CAAC,EAAE,CAACH,IAAI,EAAEC,KAAK,CAAC,CAAC;EAEjBJ,SAAS,CAAC,MAAM;IACdO,IAAI,EAAE;EACR,CAAC,EAAE,CAACA,IAAI,CAAC,CAAC;EAEV,MAAMI,MAAM,GAAGZ,WAAW,CACxB,MAAOa,UAAkB,IAAK;IAC5B,MAAMd,cAAc,CAACe,SAAS,CAACV,IAAI,EAAES,UAAU,EAAER,KAAK,CAAC;IACvDG,IAAI,EAAE;EACR,CAAC,EACD,CAACJ,IAAI,EAAEC,KAAK,EAAEG,IAAI,CAAC,CACpB;EAED,MAAMO,MAAM,GAAGf,WAAW,CAAC,YAAY;IACrC,MAAMD,cAAc,CAACiB,MAAM,CAACZ,IAAI,EAAEC,KAAK,CAAC;IACxCE,UAAU,CAAC,IAAI,CAAC;EAClB,CAAC,EAAE,CAACH,IAAI,EAAEC,KAAK,CAAC,CAAC;EAEjB,OAAO;IACLC,OAAO;IACPE,IAAI;IACJI,MAAM;IACNG;EACF,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["RNCloudStorage"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,OAAOA,cAAc,MAAM,kBAAkB;AAC7C,cAAc,cAAc;AAC5B,cAAc,sBAAsB;AAEpC,eAAeA,cAAc"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["StorageScope"],"sourceRoot":"../../../src","sources":["types/main.ts"],"mappings":"AAAA,WAAYA,YAAY,0BAAZA,YAAY;EAAZA,YAAY;EAAZA,YAAY;EAAA,OAAZA,YAAY;AAAA"}
|