This commit is contained in:
2020-04-24 14:05:43 +00:00
parent f35754632c
commit 4c8799ec4d
4 changed files with 62 additions and 21 deletions

View File

@@ -263,14 +263,22 @@ export default {
///////////////////////////// /////////////////////////////
// Attachment download URL // Attachment download URL
// //
downloadUrl(fileId) { downloadUrl(fileId, ctype) {
//http://localhost:7575/api/v8/Attachment/download/100?t=sssss //http://localhost:7575/api/v8/Attachment/download/100?t=sssss
return this.APIUrl( //Ctype is optional and is the MIME content type, used to detect image urls at client for drag and drop ops
//in wiki but ignored by server
let url =
"Attachment/download/" + "Attachment/download/" +
fileId + fileId +
"?t=" + "?t=" +
window.$gz.store.state.downloadToken window.$gz.store.state.downloadToken;
);
if (ctype && ctype.includes("image")) {
url += "&i=1";
}
return this.APIUrl(url);
}, },
///////////////////////////// /////////////////////////////
// REPLACE END OF URL // REPLACE END OF URL

View File

@@ -267,6 +267,9 @@ export default {
// @return {string} A new string with the spliced substring. // @return {string} A new string with the spliced substring.
stringSplice: function(source, start, delCount, newSubStr) { stringSplice: function(source, start, delCount, newSubStr) {
if (source == null || source == "") { if (source == null || source == "") {
if (newSubStr) {
return newSubStr;
}
return ""; return "";
} }
return ( return (
@@ -339,6 +342,10 @@ export default {
); );
return "fa-file"; return "fa-file";
} }
if (!mimeType) {
mimeType = "";
}
mimeType = mimeType.toLowerCase(); mimeType = mimeType.toLowerCase();
let iconFromExtension = extensions[extension]; let iconFromExtension = extensions[extension];
@@ -355,6 +362,15 @@ export default {
// "gzutil:iconForFile -> No icon for file:" + fileName + " Mime:" + mimeType // "gzutil:iconForFile -> No icon for file:" + fileName + " Mime:" + mimeType
// ); // );
return "fa-file"; return "fa-file";
},
///////////////////////////////////////////////
// attempt to detect image extension name
//
isImageURI: function(uri) {
if (!uri) {
return false;
}
return this.iconForFile(uri, "") == "fa-file-image";
} }
/** /**

View File

@@ -235,7 +235,7 @@ export default {
ret.push({ ret.push({
id: o.id, id: o.id,
concurrencyToken: o.concurrencyToken, concurrencyToken: o.concurrencyToken,
url: window.$gz.api.downloadUrl(o.id), url: window.$gz.api.downloadUrl(o.id,o.contentType),
name: o.displayFileName, name: o.displayFileName,
date: window.$gz.locale.utcDateToShortDateAndTimeLocalized( date: window.$gz.locale.utcDateToShortDateAndTimeLocalized(
o.lastModified, o.lastModified,

View File

@@ -828,36 +828,53 @@ export default {
} else { } else {
//maybe an url? //maybe an url?
let url = ev.dataTransfer.getData("text"); let url = ev.dataTransfer.getData("text");
let isImageUrl = false;
console.log(ev.dataTransfer);
//todo: use alternate to "text" to look for url specifically
//if not an url then can just drop as plain text
//todo: handle both internal and external urls in the same block, because the only diff is the url itself, the rest is identical
if (url) { if (url) {
//Attachment? //Attachment?
if (url.includes("Attachment/download/")) { if (url.includes("Attachment/download/")) {
//it's an attachment url so fixup accordingly //it's an attachment url so fixup accordingly
//DROP:Possible url http://localhost:7575/api/v8.0/Attachment/download/4?t=CYs1xUgjdyaWmcq8rXlPpNNSaKpiMt8Xhi7mKRGeg8o wiki-control.vue:826 //i paramter added by gzapi::downloadUrl function
//cow(.*)milk isImageUrl = url.includes("&i=");
let m = url.match(/Attachment\/download\/(.*)\?t=/); let m = url.match(/Attachment\/download\/(.*)\?t=/);
if (m.length > 1) { if (m.length > 1) {
url = "[ATTACH:" + m[1] + "]"; url = "[ATTACH:" + m[1] + "]";
} else { } else {
url = null; url = null;
} }
if (url != null) { } else {
//insert into textarea //External url, sniff out if it's an image
let txt = this.getSelectedText(); isImageUrl = window.$gz.util.isImageURI(url);
if (txt) { }
if (url != null) {
//insert into textarea
let txt = this.getSelectedText();
if (txt) {
if (isImageUrl) {
this.replaceSelectedText( this.replaceSelectedText(
"![" + txt + "](" + url + ' "' + txt + '") \n' + txt //keep original selected text otherwise it will vanish "![" + txt + "](" + url + ' "' + txt + '") \n' + txt //keep original selected text otherwise it will vanish
); );
} else { } else {
this.replaceSelectedText("![](" + url + ")"); //regular url not image
this.replaceSelectedText(
"[" + txt + "](" + url + ' "' + txt + '")\n'
);
}
} else {
//No selected text
if (isImageUrl) {
this.replaceSelectedText("![](" + url + ")\n");
} else {
//regular no text non image url
this.replaceSelectedText("<" + url + ">\n");
} }
//trigger dirty change
this.handleInput(this.localVal);
} }
console.log("processed url:", url); //trigger dirty change
} else { this.handleInput(this.localVal);
//External url
//todo: this
console.log("STUB: Handle external url drop");
} }
//handle accordingly //handle accordingly