From 732190287fb2f8b2ec401de3491e6211a0a1d26e Mon Sep 17 00:00:00 2001 From: Nurahmadie Date: Mon, 1 Aug 2016 03:45:14 +0700 Subject: [PATCH] Version 0.2.0 - Refactor to allow URL templating, instead of using prefix - Add support to view listing from different domain. --- app/thumbnail.js | 22 +++++++++++++++++++--- app/utils.js | 10 ++++++---- package.json | 2 +- vyw.config.ls | 39 +++++++++++++++++++++++++++------------ 4 files changed, 53 insertions(+), 20 deletions(-) diff --git a/app/thumbnail.js b/app/thumbnail.js index 754700f..a35c596 100644 --- a/app/thumbnail.js +++ b/app/thumbnail.js @@ -5,7 +5,7 @@ import {join, byteSize} from './utils'; * It reads `thumbnailer` property from config which possibly * contains: * * For example, to use rsz.io service you can specify this @@ -22,7 +22,7 @@ import {join, byteSize} from './utils'; * @return {string} URL to the thumbnail image. */ export function thumbnail(source, href) { - if (window.vyw.thumbnailer === 'local' && + if (window.vyw.thumbnailer === 'original-image' && byteSize(window.vyw.maxSize) >= (0|source.size)) { return href; } @@ -30,5 +30,21 @@ export function thumbnail(source, href) { } function genThumbnail(href) { - return window.vyw.thumbnailer.replace(//g, href); + var path, url, hostname, host; + try { + if (href.indexOf('//') === 0) { + href = window.location.protocol + href; + } + url = new URL(href); + path = url.pathname; + } catch (e) { /* href doesn't specify domain */ + path = href; + url = window.location; + } + host = url.host; + hostname = url.hostname; + return window.vyw.thumbnailer + .replace(//g, host) + .replace(//g, hostname) + .replace(/\/?/g, path); } diff --git a/app/utils.js b/app/utils.js index 460e9d6..795c6ec 100644 --- a/app/utils.js +++ b/app/utils.js @@ -20,8 +20,9 @@ export function join(fragments) { * @return {string} The URL path */ export function hashToURL(hash) { - const prefix = window.vyw.prefix; - return join(prefix, hash.substr(1)); + const endpoint = window.vyw.listEndpoint; + const path = hash.substr(1) === '' ? '/' : hash.substr(1); + return endpoint.replace(/\/?/g, path); } @@ -40,11 +41,12 @@ export function pathForHref(current, item) { if (item.type === 'directory') { return `#${join(current, item.name)}`; } - return join(window.vyw.filePrefix, current, item.name); + const fileUrl = window.vyw.fileEndpoint; + return fileUrl.replace(/\/?/g, join(current, item.name)); } -const imgType = ['bmp', 'jpg', 'jpeg', 'gif', 'png', 'webp']; +const imgType = window.vyw.supportedImageType; /** * `fileType` returns file type of the given object diff --git a/package.json b/package.json index e3e8160..6389061 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vyw", - "version": "0.1.0", + "version": "0.2.0", "description": "View your file, backed only with nginx", "main": "app.js", "dependencies": { diff --git a/vyw.config.ls b/vyw.config.ls index 9127952..88be3c3 100644 --- a/vyw.config.ls +++ b/vyw.config.ls @@ -1,27 +1,42 @@ window.vyw = - /* + /** * You may want to change this if your nginx - * json listing was set in different location + * json listing was set in different location, + * `` will be replaced by its respective + * path to the directory listing. Listing can accept + * url with different domain, but the server should + * support CORS. */ - prefix: '/.json' + list-endpoint: '.json' - /* + /** * this prefix will be applied when accessing files * you can change this according to your real file location - * as set in nginx + * as set in nginx. Or you can specify file path with different + * domain, as long as it's corresponds with `` value. */ - file-prefix: '/' + file-endpoint: '' - /* + /** * specify thumbnailer service to use, - * `` will be substituted with - * its respective file path + * `` will be substituted with + * its respective file path, you can specify + * `original-image` which essentially equal to specifying + * `//`, but then displaying thumbnail will be + * stricted to file with maximum size = + * If host domain is needed in thumbnailer, + * `` and `` is available to use. */ - thumbnailer: \//192.168.77.128 + thumbnailer: \original-image - /* + /** * this set max file size to allow thumbnail generation * `0` means no thumbnail. - * Only used if thumbnailer value is `local` + * Only used if thumbnailer value is `original-image`. */ max-size: \100M + + /** + * Image type supported by thumbnailer. + */ + supported-image-type: [ \jpg \jpeg \gif \png ]