@rsweeten/dropbox-sync 0.1.2 → 0.1.3
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/.github/workflows/test-pr.yml +30 -0
- package/README.md +207 -1
- package/__mocks__/nuxt/app.js +20 -0
- package/dist/adapters/__tests__/angular.spec.d.ts +1 -0
- package/dist/adapters/__tests__/angular.spec.js +237 -0
- package/dist/adapters/__tests__/next.spec.d.ts +1 -0
- package/dist/adapters/__tests__/next.spec.js +179 -0
- package/dist/adapters/__tests__/nuxt.spec.d.ts +1 -0
- package/dist/adapters/__tests__/nuxt.spec.js +145 -0
- package/dist/adapters/__tests__/svelte.spec.d.ts +1 -0
- package/dist/adapters/__tests__/svelte.spec.js +149 -0
- package/dist/core/__tests__/auth.spec.d.ts +1 -0
- package/dist/core/__tests__/auth.spec.js +83 -0
- package/dist/core/__tests__/client.spec.d.ts +1 -0
- package/dist/core/__tests__/client.spec.js +102 -0
- package/dist/core/__tests__/socket.spec.d.ts +1 -0
- package/dist/core/__tests__/socket.spec.js +122 -0
- package/dist/core/__tests__/sync.spec.d.ts +1 -0
- package/dist/core/__tests__/sync.spec.js +375 -0
- package/dist/core/sync.js +30 -11
- package/jest.config.js +24 -0
- package/jest.setup.js +38 -0
- package/package.json +4 -1
- package/src/adapters/__tests__/angular.spec.ts +338 -0
- package/src/adapters/__tests__/next.spec.ts +240 -0
- package/src/adapters/__tests__/nuxt.spec.ts +185 -0
- package/src/adapters/__tests__/svelte.spec.ts +194 -0
- package/src/core/__tests__/auth.spec.ts +142 -0
- package/src/core/__tests__/client.spec.ts +128 -0
- package/src/core/__tests__/socket.spec.ts +153 -0
- package/src/core/__tests__/sync.spec.ts +508 -0
- package/src/core/sync.ts +53 -26
package/src/core/sync.ts
CHANGED
|
@@ -13,26 +13,26 @@ import type {
|
|
|
13
13
|
|
|
14
14
|
// Define interface for Dropbox file entries
|
|
15
15
|
interface DropboxFileEntry {
|
|
16
|
-
'.tag': string
|
|
17
|
-
path_display?: string
|
|
18
|
-
[key: string]: any
|
|
16
|
+
'.tag': string
|
|
17
|
+
path_display?: string
|
|
18
|
+
[key: string]: any
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
// Define interface for Dropbox API responses
|
|
22
22
|
interface DropboxListFolderResponse {
|
|
23
23
|
result: {
|
|
24
|
-
entries: DropboxFileEntry[]
|
|
25
|
-
has_more: boolean
|
|
26
|
-
cursor: string
|
|
27
|
-
}
|
|
24
|
+
entries: DropboxFileEntry[]
|
|
25
|
+
has_more: boolean
|
|
26
|
+
cursor: string
|
|
27
|
+
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
interface DropboxDownloadResponse {
|
|
31
31
|
result: {
|
|
32
|
-
fileBlob?: Blob
|
|
33
|
-
fileBinary?: string
|
|
34
|
-
[key: string]: any
|
|
35
|
-
}
|
|
32
|
+
fileBlob?: Blob
|
|
33
|
+
fileBinary?: string
|
|
34
|
+
[key: string]: any
|
|
35
|
+
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export function createSyncMethods(
|
|
@@ -61,8 +61,13 @@ export function createSyncMethods(
|
|
|
61
61
|
|
|
62
62
|
// If it's a Blob, convert it to a Buffer
|
|
63
63
|
if (typeof Blob !== 'undefined' && data instanceof Blob) {
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
// In browser or when Blob has arrayBuffer method
|
|
65
|
+
if (data.arrayBuffer && typeof data.arrayBuffer === 'function') {
|
|
66
|
+
const arrayBuffer = await data.arrayBuffer()
|
|
67
|
+
return Buffer.from(arrayBuffer)
|
|
68
|
+
}
|
|
69
|
+
// Fallback for environments where arrayBuffer might not exist
|
|
70
|
+
return Buffer.from(String(data))
|
|
66
71
|
}
|
|
67
72
|
|
|
68
73
|
// If it's a plain ArrayBuffer
|
|
@@ -75,6 +80,17 @@ export function createSyncMethods(
|
|
|
75
80
|
return Buffer.from(data)
|
|
76
81
|
}
|
|
77
82
|
|
|
83
|
+
// For Jest mock objects that mimic Blob behavior
|
|
84
|
+
if (
|
|
85
|
+
data &&
|
|
86
|
+
typeof data === 'object' &&
|
|
87
|
+
'arrayBuffer' in data &&
|
|
88
|
+
typeof data.arrayBuffer === 'function'
|
|
89
|
+
) {
|
|
90
|
+
const arrayBuffer = await data.arrayBuffer()
|
|
91
|
+
return Buffer.from(arrayBuffer)
|
|
92
|
+
}
|
|
93
|
+
|
|
78
94
|
// If we don't know what it is, throw an error
|
|
79
95
|
throw new Error(`Unsupported data type: ${typeof data}`)
|
|
80
96
|
}
|
|
@@ -124,10 +140,10 @@ export function createSyncMethods(
|
|
|
124
140
|
|
|
125
141
|
async function fetchFolderContents(path: string) {
|
|
126
142
|
try {
|
|
127
|
-
const response = await dropbox.filesListFolder({
|
|
143
|
+
const response = (await dropbox.filesListFolder({
|
|
128
144
|
path,
|
|
129
145
|
recursive: true,
|
|
130
|
-
}) as unknown as DropboxListFolderResponse
|
|
146
|
+
})) as unknown as DropboxListFolderResponse
|
|
131
147
|
|
|
132
148
|
for (const entry of response.result.entries) {
|
|
133
149
|
if (
|
|
@@ -151,9 +167,9 @@ export function createSyncMethods(
|
|
|
151
167
|
}
|
|
152
168
|
|
|
153
169
|
async function continueListing(cursor: string) {
|
|
154
|
-
const response = await dropbox.filesListFolderContinue({
|
|
170
|
+
const response = (await dropbox.filesListFolderContinue({
|
|
155
171
|
cursor: cursor,
|
|
156
|
-
}) as unknown as DropboxListFolderResponse
|
|
172
|
+
})) as unknown as DropboxListFolderResponse
|
|
157
173
|
|
|
158
174
|
for (const entry of response.result.entries) {
|
|
159
175
|
if (
|
|
@@ -209,8 +225,9 @@ export function createSyncMethods(
|
|
|
209
225
|
options?.localDir || path.join(process.cwd(), 'public', 'img')
|
|
210
226
|
const dropboxDir = options?.dropboxDir || ''
|
|
211
227
|
|
|
212
|
-
|
|
213
|
-
const
|
|
228
|
+
// Use the public API methods instead of internal functions
|
|
229
|
+
const localFiles = await this.scanLocalFiles(localDir)
|
|
230
|
+
const dropboxFiles = await this.scanDropboxFiles(dropboxDir)
|
|
214
231
|
|
|
215
232
|
// Normalize paths for comparison
|
|
216
233
|
const normalizedDropboxFiles = dropboxFiles.map(normalizePath)
|
|
@@ -377,16 +394,18 @@ export function createSyncMethods(
|
|
|
377
394
|
)
|
|
378
395
|
|
|
379
396
|
// Download the file from Dropbox with proper error handling
|
|
380
|
-
const response = await dropbox.filesDownload({
|
|
397
|
+
const response = (await dropbox.filesDownload({
|
|
381
398
|
path: dropboxFilePath,
|
|
382
|
-
}) as unknown as DropboxDownloadResponse
|
|
399
|
+
})) as unknown as DropboxDownloadResponse
|
|
383
400
|
|
|
384
401
|
// Get file content - handle different possible response formats
|
|
385
|
-
let fileContent: Buffer
|
|
386
|
-
const responseResult = response.result
|
|
402
|
+
let fileContent: Buffer
|
|
403
|
+
const responseResult = response.result
|
|
387
404
|
|
|
388
405
|
if (responseResult.fileBlob) {
|
|
389
|
-
fileContent = await blobToBuffer(
|
|
406
|
+
fileContent = await blobToBuffer(
|
|
407
|
+
responseResult.fileBlob
|
|
408
|
+
)
|
|
390
409
|
} else if (responseResult.fileBinary) {
|
|
391
410
|
fileContent = Buffer.from(
|
|
392
411
|
responseResult.fileBinary,
|
|
@@ -395,11 +414,19 @@ export function createSyncMethods(
|
|
|
395
414
|
} else {
|
|
396
415
|
// For Node.js environment, Dropbox might return content in different properties
|
|
397
416
|
const contentKey = Object.keys(responseResult).find(
|
|
398
|
-
(key) =>
|
|
417
|
+
(key) =>
|
|
418
|
+
[
|
|
419
|
+
'content',
|
|
420
|
+
'fileContent',
|
|
421
|
+
'file',
|
|
422
|
+
'data',
|
|
423
|
+
].includes(key)
|
|
399
424
|
)
|
|
400
425
|
|
|
401
426
|
if (contentKey) {
|
|
402
|
-
fileContent = Buffer.from(
|
|
427
|
+
fileContent = Buffer.from(
|
|
428
|
+
responseResult[contentKey]
|
|
429
|
+
)
|
|
403
430
|
} else {
|
|
404
431
|
throw new Error(
|
|
405
432
|
`Could not find file content in Dropbox response for ${dropboxFilePath}`
|