Skip to content

Commit

Permalink
Version 0.2.0
Browse files Browse the repository at this point in the history
- Refactor to allow URL templating, instead of using prefix
- Add support to view listing from different domain.
  • Loading branch information
fudanchii committed Jul 31, 2016
1 parent 471dff3 commit 7321902
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 20 deletions.
22 changes: 19 additions & 3 deletions app/thumbnail.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {join, byteSize} from './utils';
* It reads `thumbnailer` property from config which possibly
* contains:
* <ul>
* <li>`local`
* <li>`original-image`
* <li>URL template for thumbnail services
* </ul>
* For example, to use rsz.io service you can specify this
Expand All @@ -22,13 +22,29 @@ 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;
}
return genThumbnail(href);
}

function genThumbnail(href) {
return window.vyw.thumbnailer.replace(/<FILEPATH>/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(/<HOST>/g, host)
.replace(/<HOSTNAME>/g, hostname)
.replace(/\/?<PATHNAME>/g, path);
}
10 changes: 6 additions & 4 deletions app/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(/\/?<PATHNAME>/g, path);
}


Expand All @@ -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(/\/?<PATHNAME>/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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
39 changes: 27 additions & 12 deletions vyw.config.ls
Original file line number Diff line number Diff line change
@@ -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,
* `<PATHNAME>` 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: '<PATHNAME>.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 `<PATHNAME>` value.
*/
file-prefix: '/'
file-endpoint: '<PATHNAME>'

/*
/**
* specify thumbnailer service to use,
* `<FILEPATH>` will be substituted with
* its respective file path
* `<PATHNAME>` will be substituted with
* its respective file path, you can specify
* `original-image` which essentially equal to specifying
* `//<HOST><PATHNAME>`, but then displaying thumbnail will be
* stricted to file with maximum size = <value of maxSize>
* If host domain is needed in thumbnailer,
* `<HOST>` and `<HOSTNAME>` is available to use.
*/
thumbnailer: \//192.168.77.128<FILEPATH>
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 ]

0 comments on commit 7321902

Please sign in to comment.