UNPKG

ravendb

Version:
89 lines 3.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetAttachmentCommand = exports.GetAttachmentOperation = void 0; const HttpUtil_js_1 = require("../../../Utility/HttpUtil.js"); const index_js_1 = require("../../Attachments/index.js"); const RavenCommand_js_1 = require("../../../Http/RavenCommand.js"); const index_js_2 = require("../../../Exceptions/index.js"); const StringUtil_js_1 = require("../../../Utility/StringUtil.js"); class GetAttachmentOperation { _documentId; _name; _type; _changeVector; get resultType() { return "CommandResult"; } constructor(documentId, name, type, changeVector) { this._documentId = documentId; this._name = name; this._type = type; this._changeVector = changeVector; } getCommand(store, conventions, cache) { return new GetAttachmentCommand(this._documentId, this._name, this._type, this._changeVector); } } exports.GetAttachmentOperation = GetAttachmentOperation; class GetAttachmentCommand extends RavenCommand_js_1.RavenCommand { _documentId; _name; _type; _changeVector; constructor(documentId, name, type, changeVector) { super(); this.result = null; if (StringUtil_js_1.StringUtil.isNullOrWhitespace(documentId)) { (0, index_js_2.throwError)("InvalidArgumentException", "DocumentId cannot be null or empty"); } if (StringUtil_js_1.StringUtil.isNullOrWhitespace(name)) { (0, index_js_2.throwError)("InvalidArgumentException", "Name cannot be null or empty"); } if (type !== "Document" && !changeVector) { (0, index_js_2.throwError)("InvalidArgumentException", "Change vector cannot be null for attachment type " + type); } this._documentId = documentId; this._name = name; this._type = type; this._changeVector = changeVector; this._responseType = "Empty"; } createRequest(node) { const uri = node.url + "/databases/" + node.database + "/attachments?id=" + encodeURIComponent(this._documentId) + "&name=" + encodeURIComponent(this._name); if (this._type !== "Document") { const body = this._serializer.serialize({ Type: this._type, ChangeVector: this._changeVector }); return { uri, method: "POST", body }; } return { uri }; } async processResponse(cache, response, bodyStream, url) { const contentType = response.headers.get("content-type"); const changeVector = (0, HttpUtil_js_1.getEtagHeader)(response); const hash = response.headers.get("attachment-hash"); let size = 0; const sizeHeader = response.headers.get("attachment-size"); if (sizeHeader) { size = Number.parseInt(sizeHeader, 10); } const details = { name: this._name, documentId: this._documentId, contentType, hash, changeVector, size }; this.result = new index_js_1.AttachmentResult(bodyStream, details, response); return "Manually"; } get isReadRequest() { return true; } } exports.GetAttachmentCommand = GetAttachmentCommand; //# sourceMappingURL=GetAttachmentOperation.js.map