MCPcopy Create free account
hub / github.com/bewcloud/bewcloud / buildPropFindResponse

Function buildPropFindResponse

lib/utils/webdav.ts:157–254  ·  view source on GitHub ↗
(
  properties: string[],
  rootPath: string,
  queryPath: string,
  depth: number | null = null,
)

Source from the content-addressed store, hash-verified

155}
156
157export async function buildPropFindResponse(
158 properties: string[],
159 rootPath: string,
160 queryPath: string,
161 depth: number | null = null,
162): Promise<Record<string, any>> {
163 const filePaths = await getFilePaths(join(rootPath, queryPath), depth);
164
165 const response: Record<string, any> = {
166 xml: {
167 '@version': '1.0',
168 '@encoding': 'UTF-8',
169 },
170 multistatus: {
171 '@xmlns:D': 'DAV:',
172 response: [],
173 },
174 };
175
176 for (const filePath of filePaths) {
177 try {
178 const stat = await Deno.stat(filePath);
179
180 const isDirectory = stat.isDirectory || stat.isSymlink;
181 const prop: Record<string, any> = {};
182 const notFound: Record<string, any> = {};
183
184 for (const propKey of properties) {
185 switch (propKey) {
186 case 'displayname':
187 prop.displayname = isDirectory ? filePath.split('/').filter(Boolean).pop() : filePath.split('/').pop();
188 break;
189 case 'getcontentlength':
190 if (!isDirectory) {
191 prop.getcontentlength = stat.size?.toString() || '0';
192 }
193 break;
194 case 'getcontenttype':
195 if (!isDirectory) {
196 prop.getcontenttype = lookup(filePath);
197 }
198 break;
199 case 'resourcetype':
200 prop.resourcetype = isDirectory ? { collection: { '@xmlns:D': 'DAV:' } } : {};
201 break;
202 case 'getlastmodified':
203 prop.getlastmodified = stat.mtime?.toUTCString() || '';
204 break;
205 case 'creationdate':
206 prop.creationdate = stat.birthtime?.toUTCString() || '';
207 break;
208 case 'getetag':
209 prop.etag = stat.mtime?.toUTCString();
210 break;
211 case 'getctag':
212 prop.ctag = stat.mtime?.toUTCString();
213 break;
214 case 'allprop':

Callers 1

handlerFunction · 0.90

Calls 3

getFilePathsFunction · 0.85
encodeFilePathFunction · 0.85
addDavPrefixToKeysFunction · 0.85

Tested by

no test coverage detected