gdrivekit 1.0.6 → 1.0.8

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.
Files changed (3) hide show
  1. package/README.md +6 -7
  2. package/dist/index.js +51 -24
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -59,8 +59,7 @@ After that, you **don’t need to call it again** unless you delete your tokens
59
59
  Once tokens are generated, you can initialize the Google Drive service and perform file operations:
60
60
 
61
61
  ```ts
62
- import { operations } from "gdrivekit";
63
- import { initDriveService } from "./drivers/services";
62
+ import { initDriveService, operations } from "gdrivekit";
64
63
 
65
64
  async function main() {
66
65
  initDriveService();
@@ -81,14 +80,13 @@ main();
81
80
 
82
81
  | Method | Description |
83
82
  | ------------------ | ----------------------------------------- |
83
+ | `readFileData()` | Read file content |
84
84
  | `uploadFile()` | Upload a new file to Google Drive |
85
85
  | `downloadFile()` | Download a file from Drive |
86
86
  | `deleteFile()` | Permanently delete a file |
87
87
  | `renameFile()` | Rename an existing file |
88
88
  | `updateFile()` | Update file metadata or content |
89
89
  | `getFileInfo()` | Get details of a specific file |
90
- | `getImageMetadata()` | Get image metadata (EXIF data, dimensions, etc.) |
91
- | `getVideoMetadata()` | Get video metadata (duration, dimensions, etc.) |
92
90
  | `getCompleteFileInfo()` | Get complete file metadata including all fields |
93
91
  | `moveFile()` | Move file to another folder using file ID |
94
92
  | `moveFileByName()` | Move file by its name |
@@ -108,7 +106,7 @@ main();
108
106
  | --------------------- | --------------------------------------- |
109
107
  | `createFolder()` | Create a new folder |
110
108
  | `deleteFolder()` | Delete an existing folder |
111
- | `listFoldersByName()` | List all folders with a specific name |
109
+ | `listFoldersByName()` | List all folders with a specific name |
112
110
  | `listAllFolders()` | List all folders in Drive |
113
111
  | `listFilesInFolder()` | List all files within a specific folder |
114
112
  | `listFoldersInFolder()` | List all folders within a specific folder |
@@ -145,8 +143,6 @@ main();
145
143
  | `listPresentations()`| List all presentation files |
146
144
  | `listDocs()` | List all docs files |
147
145
 
148
-
149
-
150
146
  ---
151
147
 
152
148
  ### 🧩 **Batch Operations**
@@ -164,6 +160,7 @@ main();
164
160
  | Method | Description |
165
161
  | --------------------- | --------------------------- |
166
162
  | `fileExists()` | Check if a file exists |
163
+ | `getStorageQuota()` | Get storage quota information |
167
164
  | `getFolderIdByName()` | Fetch folder ID by its name |
168
165
  | `getFileIdByName()` | Fetch file ID by its name |
169
166
 
@@ -177,6 +174,8 @@ main();
177
174
  | `updateJsonFieldAndValues()` | Update an existing field in a JSON file |
178
175
  | `deleteJsonFieldAndKeys()` | Delete a field from a JSON file |
179
176
 
177
+ ---
178
+
180
179
  ### ⚡ Example: Upload a File
181
180
 
182
181
  ```ts
package/dist/index.js CHANGED
@@ -778734,6 +778734,7 @@ __export(exports_operations, {
778734
778734
  listArchives: () => listArchives,
778735
778735
  listAllFolders: () => listAllFolders,
778736
778736
  getVideoMetadata: () => getVideoMetadata,
778737
+ getStorageQuota: () => getStorageQuota,
778737
778738
  getImageMetadata: () => getImageMetadata,
778738
778739
  getFolderIdByName: () => getFolderIdByName,
778739
778740
  getFileInfo: () => getFileInfo,
@@ -778785,6 +778786,28 @@ var MIME_TYPES = {
778785
778786
  };
778786
778787
 
778787
778788
  // operations.ts
778789
+ async function searchByNameHelper(name, type, searchType = "exact") {
778790
+ let query = searchType === "exact" ? `name='${name}'` : `name contains '${name}'`;
778791
+ if (type === "folder") {
778792
+ query += ` and mimeType='${MIME_TYPES.FOLDER}'`;
778793
+ } else if (type === "file") {
778794
+ query += ` and mimeType!='${MIME_TYPES.FOLDER}'`;
778795
+ }
778796
+ query += " and trashed=false";
778797
+ return await driveService.listFiles({ query });
778798
+ }
778799
+ async function getIdByNameHelper(name, type) {
778800
+ const result = await searchByNameHelper(name, type, "exact");
778801
+ if (result.success && result.data?.files.length) {
778802
+ const item = result.data.files[0];
778803
+ return {
778804
+ success: true,
778805
+ id: item.id,
778806
+ item
778807
+ };
778808
+ }
778809
+ return { success: false, error: `${type ? type.charAt(0).toUpperCase() + type.slice(1) : "Item"} not found` };
778810
+ }
778788
778811
  async function readFileData(fileId) {
778789
778812
  const response = await driveService.readFileData(fileId);
778790
778813
  if (response.success && response.data) {
@@ -778834,11 +778857,13 @@ async function moveFile(fileId, newFolderId) {
778834
778857
  });
778835
778858
  }
778836
778859
  async function moveFileByName(fileName, folderName) {
778837
- const fileResult = await getFileIdByName(fileName);
778860
+ const [fileResult, folderResult] = await Promise.all([
778861
+ getFileIdByName(fileName),
778862
+ getFolderIdByName(folderName)
778863
+ ]);
778838
778864
  if (!fileResult.success || !fileResult.fileId) {
778839
778865
  return { success: false, error: "File not found" };
778840
778866
  }
778841
- const folderResult = await getFolderIdByName(folderName);
778842
778867
  if (!folderResult.success || !folderResult.folderId) {
778843
778868
  return { success: false, error: "Destination folder not found" };
778844
778869
  }
@@ -778978,9 +779003,7 @@ async function deleteFolder(folderId) {
778978
779003
  return await driveService.deleteFile(folderId);
778979
779004
  }
778980
779005
  async function listFoldersByName(folderName) {
778981
- return await driveService.listFiles({
778982
- query: `name='${folderName}' and mimeType='${MIME_TYPES.FOLDER}' and trashed=false`
778983
- });
779006
+ return await searchByNameHelper(folderName, "folder", "exact");
778984
779007
  }
778985
779008
  async function listAllFolders() {
778986
779009
  return await driveService.listFiles({
@@ -778998,14 +779021,10 @@ async function listFilesInFolder(folderId) {
778998
779021
  });
778999
779022
  }
779000
779023
  async function searchByName(fileName) {
779001
- return await driveService.listFiles({
779002
- query: `name contains '${fileName}' and trashed=false`
779003
- });
779024
+ return await searchByNameHelper(fileName, "file", "contains");
779004
779025
  }
779005
779026
  async function searchByExactName(fileName) {
779006
- return await driveService.listFiles({
779007
- query: `name='${fileName}' and trashed=false`
779008
- });
779027
+ return await searchByNameHelper(fileName, "file", "exact");
779009
779028
  }
779010
779029
  async function searchByType(type) {
779011
779030
  const mimeTypes = {
@@ -779131,30 +779150,30 @@ async function fileExists(fileName) {
779131
779150
  const result = await searchByExactName(fileName);
779132
779151
  return result.success && (result.data?.files.length || 0) > 0;
779133
779152
  }
779153
+ async function getStorageQuota() {
779154
+ return await driveService.getStorageQuota();
779155
+ }
779134
779156
  async function getFolderIdByName(folderName) {
779135
- const result = await driveService.listFiles({
779136
- query: `name='${folderName}' and mimeType='${MIME_TYPES.FOLDER}' and trashed=false`,
779137
- pageSize: 1
779138
- });
779139
- if (result.success && result.data?.files.length) {
779157
+ const result = await getIdByNameHelper(folderName, "folder");
779158
+ if (result.success) {
779140
779159
  return {
779141
779160
  success: true,
779142
- folderId: result.data.files[0]?.id || "",
779143
- folder: result.data.files[0]
779161
+ folderId: result.id || "",
779162
+ folder: result.item
779144
779163
  };
779145
779164
  }
779146
- return { success: false, error: "Folder not found" };
779165
+ return { success: false, error: result.error };
779147
779166
  }
779148
779167
  async function getFileIdByName(fileName) {
779149
- const result = await searchByExactName(fileName);
779150
- if (result.success && result.data?.files.length) {
779168
+ const result = await getIdByNameHelper(fileName, "file");
779169
+ if (result.success) {
779151
779170
  return {
779152
779171
  success: true,
779153
- fileId: result.data.files[0]?.id || "",
779154
- file: result.data.files[0]
779172
+ fileId: result.id || "",
779173
+ file: result.item
779155
779174
  };
779156
779175
  }
779157
- return { success: false, error: "File not found" };
779176
+ return { success: false, error: result.error };
779158
779177
  }
779159
779178
  var driveOperations = {
779160
779179
  readFileData,
@@ -779191,10 +779210,18 @@ var driveOperations = {
779191
779210
  listRecentFiles,
779192
779211
  listPDFs,
779193
779212
  listImages,
779213
+ listVideos,
779214
+ listAudios,
779215
+ listArchives,
779216
+ listJSONs,
779217
+ listSheets,
779218
+ listPresentations,
779219
+ listDocs,
779194
779220
  uploadMultipleFiles,
779195
779221
  deleteMultipleFiles,
779196
779222
  downloadMultipleFiles,
779197
779223
  fileExists,
779224
+ getStorageQuota,
779198
779225
  getFolderIdByName,
779199
779226
  getFileIdByName
779200
779227
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gdrivekit",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
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",