|
1 | | -"use strict"; |
2 | | -Object.defineProperty(exports, "__esModule", { value: true }); |
3 | | -const DavContextBase_1 = require("ithit.webdav.server/DavContextBase"); |
4 | | -const path_1 = require("path"); |
5 | | -const DavFile_1 = require("./DavFile"); |
6 | | -const DavFolder_1 = require("./DavFolder"); |
7 | | -/** |
8 | | - * Implementation of {@link DavContextBase}. |
9 | | - * Resolves hierarchy items by paths. |
10 | | - */ |
11 | | -class DavContext extends DavContextBase_1.DavContextBase { |
12 | | - /** |
13 | | - * Gets user name. |
14 | | - * @remarks In case of windows authentication returns user name without domain part. |
15 | | - */ |
16 | | - get userName() { |
17 | | - const i = this.identity.Name.IndexOf("\\"); |
18 | | - return i > 0 ? this.identity.Name.Substring(i + 1, this.identity.Name.Length - i - 1) : this.identity.Name; |
19 | | - } |
20 | | - /** |
21 | | - * Initializes a new instance of the DavContext class. |
22 | | - * @param prefixes Http listener prefixes. |
23 | | - * @param repositoryPath Local path to repository. |
24 | | - */ |
25 | | - constructor(listenerContext, prefixes, principal, repositoryPath, logger, socketService) { |
26 | | - super(listenerContext, prefixes); |
27 | | - this.logger = logger; |
28 | | - this.repositoryPath = repositoryPath; |
29 | | - this.socketService = socketService; |
30 | | - if (principal !== null) { |
31 | | - this.identity = principal; |
32 | | - } |
33 | | - } |
34 | | - /** |
35 | | - * Can trim any character or set of characters from the ends of a string. |
36 | | - * Uses a Regex escapement to replace them with empty. |
37 | | - * @param source |
38 | | - * @param chars A string or array of characters desired to be trimmed. |
39 | | - * @param ignoreCase |
40 | | - * @returns {string} |
41 | | - */ |
42 | | - trim(source, chars, ignoreCase) { |
43 | | - if (chars === '') { |
44 | | - return source; |
45 | | - } |
46 | | - if (chars) { |
47 | | - const escaped = ((chars) instanceof (Array) ? chars.join() : chars).replace(/[-[\]\/{}()*+?.\\^$|]/g, "\\$&"); |
48 | | - return source.replace(new RegExp(`^[${escaped}]+|[${escaped}]+$`, 'g' + (ignoreCase |
49 | | - ? 'i' |
50 | | - : '')), ''); |
51 | | - } |
52 | | - return source.replace(/^\s+|\s+$/g, ''); |
53 | | - } |
54 | | - //$<DavContextBase.GetHierarchyItem |
55 | | - /** |
56 | | - * Creates {@link IHierarchyItem} instance by path. |
57 | | - * @param path Item relative path including query string. |
58 | | - * @returns Instance of corresponding {@link IHierarchyItem} or null if item is not found. |
59 | | - */ |
60 | | - async getHierarchyItem(path) { |
61 | | - // remove query string. |
62 | | - path = this.trim(path, [' ', '/']); |
63 | | - path = path.replace('?', ''); |
64 | | - path = path.split('/').join(`${path_1.sep}`); |
65 | | - let item; |
66 | | - item = await DavFolder_1.DavFolder.getFolder(this, path); |
67 | | - if (item !== null) { |
68 | | - return item; |
69 | | - } |
70 | | - item = await DavFile_1.DavFile.getFile(this, path); |
71 | | - if (item !== null) { |
72 | | - return item; |
73 | | - } |
74 | | - this.logger.logDebug(("Could not find item that corresponds to path: " + path)); |
75 | | - return null; |
76 | | - // no hierarchy item that corresponds to path parameter was found in the repository |
77 | | - } |
78 | | -} |
79 | | -exports.DavContext = DavContext; |
| 1 | +"use strict"; |
| 2 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 | +const DavContextBase_1 = require("ithit.webdav.server/DavContextBase"); |
| 4 | +const path_1 = require("path"); |
| 5 | +const DavFile_1 = require("./DavFile"); |
| 6 | +const DavFolder_1 = require("./DavFolder"); |
| 7 | +/** |
| 8 | + * Implementation of {@link DavContextBase}. |
| 9 | + * Resolves hierarchy items by paths. |
| 10 | + */ |
| 11 | +class DavContext extends DavContextBase_1.DavContextBase { |
| 12 | + /** |
| 13 | + * Gets user name. |
| 14 | + * @remarks In case of windows authentication returns user name without domain part. |
| 15 | + */ |
| 16 | + get userName() { |
| 17 | + const i = this.identity.Name.IndexOf("\\"); |
| 18 | + return i > 0 ? this.identity.Name.Substring(i + 1, this.identity.Name.Length - i - 1) : this.identity.Name; |
| 19 | + } |
| 20 | + /** |
| 21 | + * Initializes a new instance of the DavContext class. |
| 22 | + * @param prefixes Http listener prefixes. |
| 23 | + * @param repositoryPath Local path to repository. |
| 24 | + */ |
| 25 | + constructor(listenerContext, prefixes, principal, repositoryPath, logger, socketService) { |
| 26 | + super(listenerContext, prefixes); |
| 27 | + this.logger = logger; |
| 28 | + this.repositoryPath = repositoryPath; |
| 29 | + this.socketService = socketService; |
| 30 | + if (principal !== null) { |
| 31 | + this.identity = principal; |
| 32 | + } |
| 33 | + } |
| 34 | + /** |
| 35 | + * Can trim any character or set of characters from the ends of a string. |
| 36 | + * Uses a Regex escapement to replace them with empty. |
| 37 | + * @param source |
| 38 | + * @param chars A string or array of characters desired to be trimmed. |
| 39 | + * @param ignoreCase |
| 40 | + * @returns {string} |
| 41 | + */ |
| 42 | + trim(source, chars, ignoreCase) { |
| 43 | + if (chars === '') { |
| 44 | + return source; |
| 45 | + } |
| 46 | + if (chars) { |
| 47 | + const escaped = ((chars) instanceof (Array) ? chars.join() : chars).replace(/[-[\]\/{}()*+?.\\^$|]/g, "\\$&"); |
| 48 | + return source.replace(new RegExp(`^[${escaped}]+|[${escaped}]+$`, 'g' + (ignoreCase |
| 49 | + ? 'i' |
| 50 | + : '')), ''); |
| 51 | + } |
| 52 | + return source.replace(/^\s+|\s+$/g, ''); |
| 53 | + } |
| 54 | + //$<DavContextBase.GetHierarchyItem |
| 55 | + /** |
| 56 | + * Creates {@link IHierarchyItem} instance by path. |
| 57 | + * @param path Item relative path including query string. |
| 58 | + * @returns Instance of corresponding {@link IHierarchyItem} or null if item is not found. |
| 59 | + */ |
| 60 | + async getHierarchyItem(path) { |
| 61 | + // remove query string. |
| 62 | + path = this.trim(path, [' ', '/']); |
| 63 | + path = path.replace('?', ''); |
| 64 | + path = path.split('/').join(`${path_1.sep}`); |
| 65 | + let item; |
| 66 | + item = await DavFolder_1.DavFolder.getFolder(this, path); |
| 67 | + if (item !== null) { |
| 68 | + return item; |
| 69 | + } |
| 70 | + item = await DavFile_1.DavFile.getFile(this, path); |
| 71 | + if (item !== null) { |
| 72 | + return item; |
| 73 | + } |
| 74 | + this.logger.logDebug(("Could not find item that corresponds to path: " + path)); |
| 75 | + return null; |
| 76 | + // no hierarchy item that corresponds to path parameter was found in the repository |
| 77 | + } |
| 78 | +} |
| 79 | +exports.DavContext = DavContext; |
0 commit comments