@@ -23,6 +23,7 @@ import { DriveFile } from '../../src/driver_file.js'
2323import { DriveDirectory } from '../../src/drive_directory.js'
2424import type {
2525 WriteOptions ,
26+ CopyMoveOptions ,
2627 ObjectMetaData ,
2728 DriverContract ,
2829 SignedURLOptions ,
@@ -381,58 +382,69 @@ export class GCSDriver implements DriverContract {
381382 /**
382383 * Copies the source file to the destination. Both paths must
383384 * be within the root location.
385+ *
386+ * Use the "destinationBucket" option to copy the file to a different bucket.
384387 */
385- async copy ( source : string , destination : string , options ?: WriteOptions ) : Promise < void > {
388+ async copy ( source : string , destination : string , options ?: CopyMoveOptions ) : Promise < void > {
389+ const { destinationBucket, ...writeOptions } = options || { }
390+ const targetBucket = destinationBucket || this . options . bucket
391+
386392 debug (
387393 'copying file from %s:%s to %s:%s' ,
388394 this . options . bucket ,
389395 source ,
390- this . options . bucket ,
396+ targetBucket ,
391397 destination
392398 )
393- const bucket = this . #storage . bucket ( this . options . bucket )
394- options = options || { }
399+
400+ const sourceBucket = this . #storage . bucket ( this . options . bucket )
395401
396402 /**
397403 * Copy visibility from the source file to the
398404 * desintation when no inline visibility is
399405 * defined and not using usingUniformAcl
400406 */
401- if ( ! options . visibility && ! this . #usingUniformAcl) {
402- const [ isFilePublic ] = await bucket . file ( source ) . isPublic ( )
403- options . visibility = isFilePublic ? 'public' : 'private'
407+ if ( ! writeOptions . visibility && ! this . #usingUniformAcl) {
408+ const [ isFilePublic ] = await sourceBucket . file ( source ) . isPublic ( )
409+ writeOptions . visibility = isFilePublic ? 'public' : 'private'
404410 }
405411
406- await bucket . file ( source ) . copy ( destination , this . #getSaveOptions( options ) )
412+ const target = destinationBucket
413+ ? this . #storage. bucket ( destinationBucket ) . file ( destination )
414+ : destination
415+
416+ await sourceBucket . file ( source ) . copy ( target , this . #getSaveOptions( writeOptions ) )
407417 }
408418
409419 /**
410420 * Moves the source file to the destination. Both paths must
411421 * be within the root location.
422+ *
423+ * Use the "destinationBucket" option to move the file to a different bucket.
412424 */
413- async move ( source : string , destination : string , options ?: WriteOptions ) : Promise < void > {
414- debug (
415- 'moving file from %s:%s to %s:%s' ,
416- this . options . bucket ,
417- source ,
418- this . options . bucket ,
419- destination
420- )
425+ async move ( source : string , destination : string , options ?: CopyMoveOptions ) : Promise < void > {
426+ const { destinationBucket, ...writeOptions } = options || { }
427+ const targetBucket = destinationBucket || this . options . bucket
421428
422- const bucket = this . #storage. bucket ( this . options . bucket )
423- options = options || { }
429+ debug ( 'moving file from %s:%s to %s:%s' , this . options . bucket , source , targetBucket , destination )
430+
431+ const sourceBucket = this . #storage. bucket ( this . options . bucket )
424432
425433 /**
426434 * Copy visibility from the source file to the
427435 * desintation when no inline visibility is
428436 * defined and not using usingUniformAcl
429437 */
430- if ( ! options . visibility && ! this . #usingUniformAcl) {
431- const [ isFilePublic ] = await bucket . file ( source ) . isPublic ( )
432- options . visibility = isFilePublic ? 'public' : 'private'
438+ if ( ! writeOptions . visibility && ! this . #usingUniformAcl) {
439+ const [ isFilePublic ] = await sourceBucket . file ( source ) . isPublic ( )
440+ writeOptions . visibility = isFilePublic ? 'public' : 'private'
433441 }
434442
435- await bucket . file ( source ) . move ( destination , this . #getSaveOptions( options ) )
443+ const target = destinationBucket
444+ ? this . #storage. bucket ( destinationBucket ) . file ( destination )
445+ : destination
446+
447+ await sourceBucket . file ( source ) . move ( target , this . #getSaveOptions( writeOptions ) )
436448 }
437449
438450 /**
0 commit comments