GitHub svg media library preview support (#954)

* Append sanitize query to svg download_url

* Add svg ext to media viewable

* Append searchParam manually
This commit is contained in:
Eric Jinks 2018-01-05 05:17:52 +10:00 committed by Caleb
parent b927c8acfb
commit b8c411ce28
2 changed files with 7 additions and 3 deletions

View File

@ -94,7 +94,11 @@ export default class GitHub {
return this.api.listFiles(this.config.get('media_folder'))
.then(files => files.filter(file => file.type === 'file'))
.then(files => files.map(({ sha, name, size, download_url, path }) => {
return { id: sha, name, size, url: download_url, path };
const url = new URL(download_url);
if (url.pathname.match(/.svg$/)) {
url.search += (url.search.slice(1) === '' ? '?' : '&') + 'sanitize=true';
}
return { id: sha, name, size, url: url.href, path };
}));
}

View File

@ -21,8 +21,8 @@ import { Icon } from 'UI';
* Extensions used to determine which files to show when the media library is
* accessed from an image insertion field.
*/
const IMAGE_EXTENSIONS_VIEWABLE = [ 'jpg', 'jpeg', 'webp', 'gif', 'png', 'bmp', 'tiff' ];
const IMAGE_EXTENSIONS = [ ...IMAGE_EXTENSIONS_VIEWABLE, 'svg' ];
const IMAGE_EXTENSIONS_VIEWABLE = [ 'jpg', 'jpeg', 'webp', 'gif', 'png', 'bmp', 'tiff', 'svg' ];
const IMAGE_EXTENSIONS = [ ...IMAGE_EXTENSIONS_VIEWABLE ];
class MediaLibrary extends React.Component {