mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 17:07:07 +00:00
upload: Name the link based on the uploaded filename.
We previously parsed the filename as stored on disk, which is rather sanitized. Use as close to the original filename as possible.
This commit is contained in:
committed by
Tim Abbott
parent
8e5cdcc174
commit
8bd94b82bf
@@ -372,10 +372,13 @@ export function setup_upload(config: Config): Uppy {
|
||||
|
||||
uppy.on("upload-success", (file, response) => {
|
||||
assert(file !== undefined);
|
||||
const {url} = z.object({url: z.string()}).parse(response.body);
|
||||
const split_url = url.split("/");
|
||||
const filename = split_url.at(-1);
|
||||
const syntax_to_insert = "[" + filename + "](" + url + ")";
|
||||
const {url, filename} = z
|
||||
.object({url: z.string(), filename: z.string()})
|
||||
.parse(response.body);
|
||||
// Our markdown does not have escape characters, so we cannot link any text with brackets;
|
||||
// strip them out, if present.
|
||||
const filtered_filename = filename.replaceAll("[", "").replaceAll("]", "");
|
||||
const syntax_to_insert = "[" + filtered_filename + "](" + url + ")";
|
||||
const $text_area = config.textarea();
|
||||
const replacement_successful = compose_ui.replace_syntax(
|
||||
get_translated_status(file),
|
||||
|
||||
@@ -501,6 +501,7 @@ test("uppy_events", ({override_rewire, mock_template}) => {
|
||||
let response = {
|
||||
body: {
|
||||
url: "/user_uploads/4/cb/rue1c-MlMUjDAUdkRrEM4BTJ/copenhagen.png",
|
||||
filename: "copenhagen.png",
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user