@@ -4,8 +4,6 @@ import { WebDavRequestedResource } from '../types/webdav.types';
44import { DriveFolderService } from '../services/drive/drive-folder.service' ;
55import { DriveFileService } from '../services/drive/drive-file.service' ;
66import { DriveFileItem , DriveFolderItem } from '../types/drive.types' ;
7- import { ConflictError , NotFoundError } from './errors.utils' ;
8- import AppError from '@internxt/sdk/dist/shared/types/errors' ;
97
108export class WebDavUtils {
119 static joinURL ( ...pathComponents : string [ ] ) : string {
@@ -59,51 +57,27 @@ export class WebDavUtils {
5957 }
6058 }
6159
62- static async getDriveItemFromResource (
63- resource : WebDavRequestedResource ,
64- driveFolderService ?: DriveFolderService ,
65- driveFileService ?: DriveFileService ,
66- ) : Promise < DriveFileItem | DriveFolderItem | undefined > {
67- let item : DriveFileItem | DriveFolderItem | undefined = undefined ;
68-
69- if ( resource . type === 'folder' ) {
70- // if resource has a parentPath it means it's a subfolder then try to get it; if it throws an error it means it doesn't
71- // exist and we should throw a 409 error in compliance with the WebDAV RFC
72- // catch the error during getting parent folder and throw a 409 error in compliance with the WebDAV RFC
73- try {
74- item = await driveFolderService ?. getFolderMetadataByPath ( resource . url ) ;
75- } catch ( error ) {
76- // if the error is a 404 error, it means the resource doesn't exist
77- // in this case, throw a 409 error in compliance with the WebDAV RFC
78- if ( ( error as AppError ) . status === 404 ) {
79- throw new ConflictError ( `Resource not found on Internxt Drive at ${ resource . url } ` ) ;
80- }
81- throw error ;
82- }
83- }
84- if ( resource . type === 'file' ) {
85- try {
86- item = await driveFileService ?. getFileMetadataByPath ( resource . url ) ;
87- } catch {
88- //no op
89- }
90- }
91- return item ;
92- }
93-
94- static async getAndSearchItemFromResource ( {
60+ static async getDriveItemFromResource ( {
9561 resource,
9662 driveFolderService,
9763 driveFileService,
9864 } : {
9965 resource : WebDavRequestedResource ;
10066 driveFolderService ?: DriveFolderService ;
10167 driveFileService ?: DriveFileService ;
102- } ) : Promise < DriveFileItem | DriveFolderItem > {
103- const driveItem = await this . getDriveItemFromResource ( resource , driveFolderService , driveFileService ) ;
104- if ( ! driveItem ) {
105- throw new NotFoundError ( `Resource not found on Internxt Drive at ${ resource . url } ` ) ;
68+ } ) : Promise < DriveFileItem | DriveFolderItem | undefined > {
69+ let item : DriveFileItem | DriveFolderItem | undefined = undefined ;
70+
71+ try {
72+ if ( resource . type === 'folder' ) {
73+ item = await driveFolderService ?. getFolderMetadataByPath ( resource . url ) ;
74+ }
75+ if ( resource . type === 'file' ) {
76+ item = await driveFileService ?. getFileMetadataByPath ( resource . url ) ;
77+ }
78+ } catch {
79+ //no op
10680 }
107- return driveItem ;
81+ return item ;
10882 }
10983}
0 commit comments