mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 14:12:10 +08:00
FEATURE: replace GUID in image name uploaded from iOS (#5370)
This commit is contained in:
@ -285,6 +285,21 @@ function uploadTypeFromFileName(fileName) {
|
||||
return isAnImage(fileName) ? 'image' : 'attachment';
|
||||
}
|
||||
|
||||
function isGUID(value) {
|
||||
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
|
||||
}
|
||||
|
||||
function imageNameFromFileName(fileName) {
|
||||
const split = fileName.split('.');
|
||||
const name = split[split.length-2];
|
||||
|
||||
if (exports.isAppleDevice() && isGUID(name)) {
|
||||
return I18n.t('upload_selector.default_image_alt_text');
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
export function allowsImages() {
|
||||
return authorizesAllExtensions() || IMAGES_EXTENSIONS_REGEX.test(authorizedExtensions());
|
||||
}
|
||||
@ -309,8 +324,7 @@ export function uploadLocation(url) {
|
||||
|
||||
export function getUploadMarkdown(upload) {
|
||||
if (isAnImage(upload.original_filename)) {
|
||||
const split = upload.original_filename.split('.');
|
||||
const name = split[split.length-2];
|
||||
const name = imageNameFromFileName(upload.original_filename);
|
||||
return ``;
|
||||
} else if (!Discourse.SiteSettings.prevent_anons_from_downloading_files && (/\.(mov|mp4|webm|ogv|mp3|ogg|wav|m4a)$/i).test(upload.original_filename)) {
|
||||
return uploadLocation(upload.url);
|
||||
@ -399,5 +413,13 @@ export function determinePostReplaceSelection({ selection, needle, replacement }
|
||||
}
|
||||
}
|
||||
|
||||
export function isAppleDevice() {
|
||||
// IE has no DOMNodeInserted so can not get this hack despite saying it is like iPhone
|
||||
// This will apply hack on all iDevices
|
||||
return navigator.userAgent.match(/(iPad|iPhone|iPod)/g) &&
|
||||
navigator.userAgent.match(/Safari/g) &&
|
||||
!navigator.userAgent.match(/Trident/g);
|
||||
}
|
||||
|
||||
// This prevents a mini racer crash
|
||||
export default {};
|
||||
|
Reference in New Issue
Block a user