@nextcloud/upload
Version:
Nextcloud file upload client
139 lines (138 loc) • 4.81 kB
JavaScript
require('../assets/InvalidFilenameDialog-YDOzIzS6.css');
"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const files = require("@nextcloud/files");
const Vue = require("vue");
const index = require("./index-C4QfT-o3.cjs");
const NcDialog = require("@nextcloud/vue/dist/Components/NcDialog.js");
const NcTextField = require("@nextcloud/vue/dist/Components/NcTextField.js");
const NcNoteCard = require("@nextcloud/vue/dist/Components/NcNoteCard.js");
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
const NcDialog__default = /* @__PURE__ */ _interopDefault(NcDialog);
const NcTextField__default = /* @__PURE__ */ _interopDefault(NcTextField);
const NcNoteCard__default = /* @__PURE__ */ _interopDefault(NcNoteCard);
const _sfc_main = Vue.defineComponent({
components: {
NcDialog: NcDialog__default.default,
NcNoteCard: NcNoteCard__default.default,
NcTextField: NcTextField__default.default
},
props: {
error: {
type: files.InvalidFilenameError,
required: true
},
/**
* @deprecated just for legacy reasons, replace with function from @nextcloud/files in future
*/
validateFilename: {
type: Function,
required: true
}
},
setup() {
return {
t: index.t
};
},
data() {
return {
newName: "",
validationError: ""
};
},
computed: {
isValidName() {
return this.validationError === "";
},
isInvalidFileType() {
return this.error.reason === files.InvalidFilenameErrorReason.Extension && this.error.segment.match(/^\.\w/) !== null;
},
canRename() {
return !this.isInvalidFileType;
},
dialogButtons() {
const buttons = [
{
label: index.t("Cancel"),
type: "error",
callback: () => {
this.$emit("close", { cancel: true });
}
},
{
label: index.t("Skip"),
callback: () => {
this.$emit("close", { skip: true });
}
}
];
if (this.canRename) {
buttons.push({
label: index.t("Rename"),
type: "primary",
disabled: !this.isValidName,
callback: () => {
this.$emit("close", { rename: this.newName.trimEnd() });
}
});
}
return buttons;
}
},
watch: {
error: {
handler() {
this.validationError = this.getErrorText(this.error);
this.newName = this.error.filename;
},
immediate: true
},
newName() {
try {
this.validateFilename(this.newName.trimEnd());
this.validationError = "";
} catch (error) {
this.validationError = this.getErrorText(error);
} finally {
const textfield = this.$refs.textfield?.$el.querySelector("input");
if (textfield) {
textfield.setCustomValidity(this.validationError);
textfield.reportValidity();
}
}
}
},
methods: {
getErrorText(error) {
switch (error.reason) {
case files.InvalidFilenameErrorReason.Character:
return index.t('"{segment}" is not allowed inside a file or folder name.', { segment: error.segment });
case files.InvalidFilenameErrorReason.ReservedName:
return index.t('"{segment}" is a forbidden file or folder name.', { segment: error.segment });
case files.InvalidFilenameErrorReason.Extension:
return error.segment.match(/\.\w/) ? index.t('"{segment}" is a forbidden file type.', { segment: error.segment }) : index.t('Filenames must not end with "{segment}".', { segment: error.segment });
}
}
}
});
var _sfc_render = function render() {
var _vm = this, _c = _vm._self._c;
_vm._self._setupProxy;
return _c("NcDialog", { attrs: { "buttons": _vm.dialogButtons, "name": _vm.t("Invalid filename") }, on: { "close": function($event) {
return _vm.$emit("close", { cancel: true });
} } }, [_c("NcNoteCard", { attrs: { "severity": "error" } }, [_vm._v(" " + _vm._s(_vm.getErrorText(_vm.error)) + " " + _vm._s(_vm.t("You can either rename the file, skip this file or cancel the whole operation.")) + " ")]), _vm.canRename ? _c("NcTextField", { ref: "textfield", staticClass: "invalid-filename-dialog__input", attrs: { "error": !_vm.isValidName, "helper-text": _vm.validationError, "label": _vm.t("New filename"), "value": _vm.newName }, on: { "update:value": function($event) {
_vm.newName = $event;
} } }) : _vm._e()], 1);
};
var _sfc_staticRenderFns = [];
var __component__ = /* @__PURE__ */ index.normalizeComponent(
_sfc_main,
_sfc_render,
_sfc_staticRenderFns,
false,
null,
"3a479259"
);
const InvalidFilenameDialog = __component__.exports;
exports.default = InvalidFilenameDialog;