gdrivekit 1.0.7 → 1.0.9
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/README.md +29 -5
- package/dist/index.js +175 -28
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -80,14 +80,13 @@ main();
|
|
|
80
80
|
|
|
81
81
|
| Method | Description |
|
|
82
82
|
| ------------------ | ----------------------------------------- |
|
|
83
|
+
| `readFileData()` | Read file content |
|
|
83
84
|
| `uploadFile()` | Upload a new file to Google Drive |
|
|
84
85
|
| `downloadFile()` | Download a file from Drive |
|
|
85
86
|
| `deleteFile()` | Permanently delete a file |
|
|
86
87
|
| `renameFile()` | Rename an existing file |
|
|
87
88
|
| `updateFile()` | Update file metadata or content |
|
|
88
89
|
| `getFileInfo()` | Get details of a specific file |
|
|
89
|
-
| `getImageMetadata()` | Get image metadata (EXIF data, dimensions, etc.) |
|
|
90
|
-
| `getVideoMetadata()` | Get video metadata (duration, dimensions, etc.) |
|
|
91
90
|
| `getCompleteFileInfo()` | Get complete file metadata including all fields |
|
|
92
91
|
| `moveFile()` | Move file to another folder using file ID |
|
|
93
92
|
| `moveFileByName()` | Move file by its name |
|
|
@@ -107,7 +106,7 @@ main();
|
|
|
107
106
|
| --------------------- | --------------------------------------- |
|
|
108
107
|
| `createFolder()` | Create a new folder |
|
|
109
108
|
| `deleteFolder()` | Delete an existing folder |
|
|
110
|
-
| `listFoldersByName()` | List all folders with a specific name
|
|
109
|
+
| `listFoldersByName()` | List all folders with a specific name |
|
|
111
110
|
| `listAllFolders()` | List all folders in Drive |
|
|
112
111
|
| `listFilesInFolder()` | List all files within a specific folder |
|
|
113
112
|
| `listFoldersInFolder()` | List all folders within a specific folder |
|
|
@@ -144,8 +143,6 @@ main();
|
|
|
144
143
|
| `listPresentations()`| List all presentation files |
|
|
145
144
|
| `listDocs()` | List all docs files |
|
|
146
145
|
|
|
147
|
-
|
|
148
|
-
|
|
149
146
|
---
|
|
150
147
|
|
|
151
148
|
### 🧩 **Batch Operations**
|
|
@@ -162,13 +159,16 @@ main();
|
|
|
162
159
|
|
|
163
160
|
| Method | Description |
|
|
164
161
|
| --------------------- | --------------------------- |
|
|
162
|
+
| `shareFile()` | Share a file with a user |
|
|
165
163
|
| `fileExists()` | Check if a file exists |
|
|
164
|
+
| `getStorageQuota()` | Get storage quota information |
|
|
166
165
|
| `getFolderIdByName()` | Fetch folder ID by its name |
|
|
167
166
|
| `getFileIdByName()` | Fetch file ID by its name |
|
|
168
167
|
|
|
169
168
|
---
|
|
170
169
|
|
|
171
170
|
### ❴❵ **Json Operation**
|
|
171
|
+
|
|
172
172
|
| Method | Description |
|
|
173
173
|
| ----------------------- | ----------------------------------------- |
|
|
174
174
|
| `readJsonFileData()` | Read JSON file content |
|
|
@@ -176,6 +176,30 @@ main();
|
|
|
176
176
|
| `updateJsonFieldAndValues()` | Update an existing field in a JSON file |
|
|
177
177
|
| `deleteJsonFieldAndKeys()` | Delete a field from a JSON file |
|
|
178
178
|
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
### ⚞ **Conversion Operation**
|
|
182
|
+
|
|
183
|
+
| Method | Description |
|
|
184
|
+
| ----------------------- | --------------------------------------------------------- |
|
|
185
|
+
| `convertTextToDocs()` | Convert a text file (`.txt`) to Google Docs format |
|
|
186
|
+
| `convertDocsToPdf()` | Convert a Google Docs file to PDF |
|
|
187
|
+
| `convertDocsToWord()` | Convert a Google Docs file to Microsoft Word (`.docx`) |
|
|
188
|
+
| `convertDocsToText()` | Convert a Google Docs file to plain text (`.txt`) |
|
|
189
|
+
| `convertCsvToSheet()` | Convert a CSV file to Google Sheets |
|
|
190
|
+
| `convertExcelToSheet()` | Convert an Excel file (`.xlsx`) to Google Sheets |
|
|
191
|
+
| `convertSheetToCsv()` | Convert a Google Sheet to CSV |
|
|
192
|
+
| `convertSheetToPdf()` | Convert a Google Sheet to PDF |
|
|
193
|
+
| `convertPptToSlides()` | Convert a PowerPoint file (`.pptx`) to Google Slides |
|
|
194
|
+
| `convertSlidesToPpt()` | Convert a Google Slides file to PowerPoint (`.pptx`) |
|
|
195
|
+
| `convertSlidesToPdf()` | Convert a Google Slides file to PDF |
|
|
196
|
+
| `convertPdfToDocs()` | Convert a PDF file to Google Docs (with OCR if supported) |
|
|
197
|
+
| `convertDrawingToPng()` | Convert a Google Drawing to PNG image |
|
|
198
|
+
| `convertDrawingToPdf()` | Convert a Google Drawing to PDF |
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
179
203
|
### ⚡ Example: Upload a File
|
|
180
204
|
|
|
181
205
|
```ts
|
package/dist/index.js
CHANGED
|
@@ -778706,6 +778706,7 @@ __export(exports_operations, {
|
|
|
778706
778706
|
uploadFile: () => uploadFile,
|
|
778707
778707
|
updateJsonFieldAndValues: () => updateJsonFieldAndValues,
|
|
778708
778708
|
updateFile: () => updateFile,
|
|
778709
|
+
shareFile: () => shareFile,
|
|
778709
778710
|
searchStarredFiles: () => searchStarredFiles,
|
|
778710
778711
|
searchSharedFiles: () => searchSharedFiles,
|
|
778711
778712
|
searchModifiedAfter: () => searchModifiedAfter,
|
|
@@ -778734,6 +778735,7 @@ __export(exports_operations, {
|
|
|
778734
778735
|
listArchives: () => listArchives,
|
|
778735
778736
|
listAllFolders: () => listAllFolders,
|
|
778736
778737
|
getVideoMetadata: () => getVideoMetadata,
|
|
778738
|
+
getStorageQuota: () => getStorageQuota,
|
|
778737
778739
|
getImageMetadata: () => getImageMetadata,
|
|
778738
778740
|
getFolderIdByName: () => getFolderIdByName,
|
|
778739
778741
|
getFileInfo: () => getFileInfo,
|
|
@@ -778749,12 +778751,23 @@ __export(exports_operations, {
|
|
|
778749
778751
|
deleteFile: () => deleteFile,
|
|
778750
778752
|
createFolder: () => createFolder,
|
|
778751
778753
|
copyFile: () => copyFile,
|
|
778754
|
+
convertTextToDocs: () => convertTextToDocs,
|
|
778755
|
+
convertSlidesToPpt: () => convertSlidesToPpt,
|
|
778756
|
+
convertSlidesToPdf: () => convertSlidesToPdf,
|
|
778757
|
+
convertSheetToPdf: () => convertSheetToPdf,
|
|
778758
|
+
convertSheetToCsv: () => convertSheetToCsv,
|
|
778759
|
+
convertPptToSlides: () => convertPptToSlides,
|
|
778760
|
+
convertPdfToDocs: () => convertPdfToDocs,
|
|
778761
|
+
convertExcelToSheet: () => convertExcelToSheet,
|
|
778762
|
+
convertDrawingToPng: () => convertDrawingToPng,
|
|
778763
|
+
convertDrawingToPdf: () => convertDrawingToPdf,
|
|
778764
|
+
convertDocsToWord: () => convertDocsToWord,
|
|
778765
|
+
convertDocsToText: () => convertDocsToText,
|
|
778766
|
+
convertDocsToPdf: () => convertDocsToPdf,
|
|
778767
|
+
convertCsvToSheet: () => convertCsvToSheet,
|
|
778752
778768
|
addJsonKeyValue: () => addJsonKeyValue
|
|
778753
778769
|
});
|
|
778754
778770
|
|
|
778755
|
-
// drivers/services.ts
|
|
778756
|
-
var driveService;
|
|
778757
|
-
|
|
778758
778771
|
// types/index.ts
|
|
778759
778772
|
var MIME_TYPES = {
|
|
778760
778773
|
FOLDER: "application/vnd.google-apps.folder",
|
|
@@ -778784,7 +778797,35 @@ var MIME_TYPES = {
|
|
|
778784
778797
|
RAR: "application/x-rar-compressed"
|
|
778785
778798
|
};
|
|
778786
778799
|
|
|
778800
|
+
// drivers/services.ts
|
|
778801
|
+
var driveService;
|
|
778802
|
+
|
|
778787
778803
|
// operations.ts
|
|
778804
|
+
async function searchByNameHelper(name, type, searchType = "exact") {
|
|
778805
|
+
let query = searchType === "exact" ? `name='${name}'` : `name contains '${name}'`;
|
|
778806
|
+
if (type === "folder") {
|
|
778807
|
+
query += ` and mimeType='${MIME_TYPES.FOLDER}'`;
|
|
778808
|
+
} else if (type === "file") {
|
|
778809
|
+
query += ` and mimeType!='${MIME_TYPES.FOLDER}'`;
|
|
778810
|
+
}
|
|
778811
|
+
query += " and trashed=false";
|
|
778812
|
+
return await driveService.listFiles({ query });
|
|
778813
|
+
}
|
|
778814
|
+
async function getIdByNameHelper(name, type) {
|
|
778815
|
+
const result = await searchByNameHelper(name, type, "exact");
|
|
778816
|
+
if (result.success && result.data?.files.length) {
|
|
778817
|
+
const item = result.data.files[0];
|
|
778818
|
+
return {
|
|
778819
|
+
success: true,
|
|
778820
|
+
id: item.id,
|
|
778821
|
+
item
|
|
778822
|
+
};
|
|
778823
|
+
}
|
|
778824
|
+
return {
|
|
778825
|
+
success: false,
|
|
778826
|
+
error: `${type ? type.charAt(0).toUpperCase() + type.slice(1) : "Item"} not found`
|
|
778827
|
+
};
|
|
778828
|
+
}
|
|
778788
778829
|
async function readFileData(fileId) {
|
|
778789
778830
|
const response = await driveService.readFileData(fileId);
|
|
778790
778831
|
if (response.success && response.data) {
|
|
@@ -778834,11 +778875,13 @@ async function moveFile(fileId, newFolderId) {
|
|
|
778834
778875
|
});
|
|
778835
778876
|
}
|
|
778836
778877
|
async function moveFileByName(fileName, folderName) {
|
|
778837
|
-
const fileResult = await
|
|
778878
|
+
const [fileResult, folderResult] = await Promise.all([
|
|
778879
|
+
getFileIdByName(fileName),
|
|
778880
|
+
getFolderIdByName(folderName)
|
|
778881
|
+
]);
|
|
778838
778882
|
if (!fileResult.success || !fileResult.fileId) {
|
|
778839
778883
|
return { success: false, error: "File not found" };
|
|
778840
778884
|
}
|
|
778841
|
-
const folderResult = await getFolderIdByName(folderName);
|
|
778842
778885
|
if (!folderResult.success || !folderResult.folderId) {
|
|
778843
778886
|
return { success: false, error: "Destination folder not found" };
|
|
778844
778887
|
}
|
|
@@ -778978,9 +779021,7 @@ async function deleteFolder(folderId) {
|
|
|
778978
779021
|
return await driveService.deleteFile(folderId);
|
|
778979
779022
|
}
|
|
778980
779023
|
async function listFoldersByName(folderName) {
|
|
778981
|
-
return await
|
|
778982
|
-
query: `name='${folderName}' and mimeType='${MIME_TYPES.FOLDER}' and trashed=false`
|
|
778983
|
-
});
|
|
779024
|
+
return await searchByNameHelper(folderName, "folder", "exact");
|
|
778984
779025
|
}
|
|
778985
779026
|
async function listAllFolders() {
|
|
778986
779027
|
return await driveService.listFiles({
|
|
@@ -778998,14 +779039,10 @@ async function listFilesInFolder(folderId) {
|
|
|
778998
779039
|
});
|
|
778999
779040
|
}
|
|
779000
779041
|
async function searchByName(fileName) {
|
|
779001
|
-
return await
|
|
779002
|
-
query: `name contains '${fileName}' and trashed=false`
|
|
779003
|
-
});
|
|
779042
|
+
return await searchByNameHelper(fileName, "file", "contains");
|
|
779004
779043
|
}
|
|
779005
779044
|
async function searchByExactName(fileName) {
|
|
779006
|
-
return await
|
|
779007
|
-
query: `name='${fileName}' and trashed=false`
|
|
779008
|
-
});
|
|
779045
|
+
return await searchByNameHelper(fileName, "file", "exact");
|
|
779009
779046
|
}
|
|
779010
779047
|
async function searchByType(type) {
|
|
779011
779048
|
const mimeTypes = {
|
|
@@ -779131,30 +779168,117 @@ async function fileExists(fileName) {
|
|
|
779131
779168
|
const result = await searchByExactName(fileName);
|
|
779132
779169
|
return result.success && (result.data?.files.length || 0) > 0;
|
|
779133
779170
|
}
|
|
779171
|
+
async function getStorageQuota() {
|
|
779172
|
+
return await driveService.getStorageQuota();
|
|
779173
|
+
}
|
|
779174
|
+
async function shareFile(fileId, emailAddress, role = "reader") {
|
|
779175
|
+
return await driveService.shareFile(fileId, emailAddress, role);
|
|
779176
|
+
}
|
|
779134
779177
|
async function getFolderIdByName(folderName) {
|
|
779135
|
-
const result = await
|
|
779136
|
-
|
|
779137
|
-
pageSize: 1
|
|
779138
|
-
});
|
|
779139
|
-
if (result.success && result.data?.files.length) {
|
|
779178
|
+
const result = await getIdByNameHelper(folderName, "folder");
|
|
779179
|
+
if (result.success) {
|
|
779140
779180
|
return {
|
|
779141
779181
|
success: true,
|
|
779142
|
-
folderId: result.
|
|
779143
|
-
folder: result.
|
|
779182
|
+
folderId: result.id || "",
|
|
779183
|
+
folder: result.item
|
|
779144
779184
|
};
|
|
779145
779185
|
}
|
|
779146
|
-
return { success: false, error:
|
|
779186
|
+
return { success: false, error: result.error };
|
|
779147
779187
|
}
|
|
779148
779188
|
async function getFileIdByName(fileName) {
|
|
779149
|
-
const result = await
|
|
779150
|
-
if (result.success
|
|
779189
|
+
const result = await getIdByNameHelper(fileName, "file");
|
|
779190
|
+
if (result.success) {
|
|
779151
779191
|
return {
|
|
779152
779192
|
success: true,
|
|
779153
|
-
fileId: result.
|
|
779154
|
-
file: result.
|
|
779193
|
+
fileId: result.id || "",
|
|
779194
|
+
file: result.item
|
|
779155
779195
|
};
|
|
779156
779196
|
}
|
|
779157
|
-
return { success: false, error:
|
|
779197
|
+
return { success: false, error: result.error };
|
|
779198
|
+
}
|
|
779199
|
+
async function convertTextToDocs(fileId) {
|
|
779200
|
+
const response = await driveService.ConversionFunction(fileId, MIME_TYPES.DOCUMENT);
|
|
779201
|
+
if (response.success && response.data)
|
|
779202
|
+
return response.data;
|
|
779203
|
+
throw new Error(response.error || "Failed to convert Text → Google Docs");
|
|
779204
|
+
}
|
|
779205
|
+
async function convertDocsToPdf(fileId) {
|
|
779206
|
+
const response = await driveService.ConversionFunction(fileId, MIME_TYPES.PDF);
|
|
779207
|
+
if (response.success && response.data)
|
|
779208
|
+
return response.data;
|
|
779209
|
+
throw new Error(response.error || "Failed to convert Docs → PDF");
|
|
779210
|
+
}
|
|
779211
|
+
async function convertDocsToWord(fileId) {
|
|
779212
|
+
const response = await driveService.ConversionFunction(fileId, MIME_TYPES.WORD);
|
|
779213
|
+
if (response.success && response.data)
|
|
779214
|
+
return response.data;
|
|
779215
|
+
throw new Error(response.error || "Failed to convert Docs → Word");
|
|
779216
|
+
}
|
|
779217
|
+
async function convertDocsToText(fileId) {
|
|
779218
|
+
const response = await driveService.ConversionFunction(fileId, MIME_TYPES.TEXT);
|
|
779219
|
+
if (response.success && response.data)
|
|
779220
|
+
return response.data;
|
|
779221
|
+
throw new Error(response.error || "Failed to convert Docs → Text");
|
|
779222
|
+
}
|
|
779223
|
+
async function convertCsvToSheet(fileId) {
|
|
779224
|
+
const response = await driveService.ConversionFunction(fileId, MIME_TYPES.SPREADSHEET);
|
|
779225
|
+
if (response.success && response.data)
|
|
779226
|
+
return response.data;
|
|
779227
|
+
throw new Error(response.error || "Failed to convert CSV → Google Sheet");
|
|
779228
|
+
}
|
|
779229
|
+
async function convertExcelToSheet(fileId) {
|
|
779230
|
+
const response = await driveService.ConversionFunction(fileId, MIME_TYPES.SPREADSHEET);
|
|
779231
|
+
if (response.success && response.data)
|
|
779232
|
+
return response.data;
|
|
779233
|
+
throw new Error(response.error || "Failed to convert Excel → Google Sheet");
|
|
779234
|
+
}
|
|
779235
|
+
async function convertSheetToCsv(fileId) {
|
|
779236
|
+
const response = await driveService.ConversionFunction(fileId, MIME_TYPES.CSV);
|
|
779237
|
+
if (response.success && response.data)
|
|
779238
|
+
return response.data;
|
|
779239
|
+
throw new Error(response.error || "Failed to convert Sheet → CSV");
|
|
779240
|
+
}
|
|
779241
|
+
async function convertSheetToPdf(fileId) {
|
|
779242
|
+
const response = await driveService.ConversionFunction(fileId, MIME_TYPES.PDF);
|
|
779243
|
+
if (response.success && response.data)
|
|
779244
|
+
return response.data;
|
|
779245
|
+
throw new Error(response.error || "Failed to convert Sheet → PDF");
|
|
779246
|
+
}
|
|
779247
|
+
async function convertPptToSlides(fileId) {
|
|
779248
|
+
const response = await driveService.ConversionFunction(fileId, MIME_TYPES.PRESENTATION);
|
|
779249
|
+
if (response.success && response.data)
|
|
779250
|
+
return response.data;
|
|
779251
|
+
throw new Error(response.error || "Failed to convert PPT → Google Slides");
|
|
779252
|
+
}
|
|
779253
|
+
async function convertSlidesToPpt(fileId) {
|
|
779254
|
+
const response = await driveService.ConversionFunction(fileId, MIME_TYPES.POWERPOINT);
|
|
779255
|
+
if (response.success && response.data)
|
|
779256
|
+
return response.data;
|
|
779257
|
+
throw new Error(response.error || "Failed to convert Slides → PPTX");
|
|
779258
|
+
}
|
|
779259
|
+
async function convertSlidesToPdf(fileId) {
|
|
779260
|
+
const response = await driveService.ConversionFunction(fileId, MIME_TYPES.PDF);
|
|
779261
|
+
if (response.success && response.data)
|
|
779262
|
+
return response.data;
|
|
779263
|
+
throw new Error(response.error || "Failed to convert Slides → PDF");
|
|
779264
|
+
}
|
|
779265
|
+
async function convertPdfToDocs(fileId) {
|
|
779266
|
+
const response = await driveService.ConversionFunction(fileId, MIME_TYPES.DOCUMENT);
|
|
779267
|
+
if (response.success && response.data)
|
|
779268
|
+
return response.data;
|
|
779269
|
+
throw new Error(response.error || "Failed to convert PDF → Google Docs");
|
|
779270
|
+
}
|
|
779271
|
+
async function convertDrawingToPng(fileId) {
|
|
779272
|
+
const response = await driveService.ConversionFunction(fileId, MIME_TYPES.PNG);
|
|
779273
|
+
if (response.success && response.data)
|
|
779274
|
+
return response.data;
|
|
779275
|
+
throw new Error(response.error || "Failed to convert Drawing → PNG");
|
|
779276
|
+
}
|
|
779277
|
+
async function convertDrawingToPdf(fileId) {
|
|
779278
|
+
const response = await driveService.ConversionFunction(fileId, MIME_TYPES.PDF);
|
|
779279
|
+
if (response.success && response.data)
|
|
779280
|
+
return response.data;
|
|
779281
|
+
throw new Error(response.error || "Failed to convert Drawing → PDF");
|
|
779158
779282
|
}
|
|
779159
779283
|
var driveOperations = {
|
|
779160
779284
|
readFileData,
|
|
@@ -779191,12 +779315,35 @@ var driveOperations = {
|
|
|
779191
779315
|
listRecentFiles,
|
|
779192
779316
|
listPDFs,
|
|
779193
779317
|
listImages,
|
|
779318
|
+
listVideos,
|
|
779319
|
+
listAudios,
|
|
779320
|
+
listArchives,
|
|
779321
|
+
listJSONs,
|
|
779322
|
+
listSheets,
|
|
779323
|
+
listPresentations,
|
|
779324
|
+
listDocs,
|
|
779194
779325
|
uploadMultipleFiles,
|
|
779195
779326
|
deleteMultipleFiles,
|
|
779196
779327
|
downloadMultipleFiles,
|
|
779328
|
+
shareFile,
|
|
779197
779329
|
fileExists,
|
|
779330
|
+
getStorageQuota,
|
|
779198
779331
|
getFolderIdByName,
|
|
779199
|
-
getFileIdByName
|
|
779332
|
+
getFileIdByName,
|
|
779333
|
+
convertTextToDocs,
|
|
779334
|
+
convertDocsToPdf,
|
|
779335
|
+
convertDocsToWord,
|
|
779336
|
+
convertDocsToText,
|
|
779337
|
+
convertCsvToSheet,
|
|
779338
|
+
convertExcelToSheet,
|
|
779339
|
+
convertSheetToCsv,
|
|
779340
|
+
convertSheetToPdf,
|
|
779341
|
+
convertPptToSlides,
|
|
779342
|
+
convertSlidesToPpt,
|
|
779343
|
+
convertSlidesToPdf,
|
|
779344
|
+
convertPdfToDocs,
|
|
779345
|
+
convertDrawingToPng,
|
|
779346
|
+
convertDrawingToPdf
|
|
779200
779347
|
};
|
|
779201
779348
|
|
|
779202
779349
|
// auth.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gdrivekit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "A lightweight Google Drive toolkit for File Management. Handle Google Drive operations easily — upload, download, and other file operations in a few lines of code.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|