mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-25 20:44:53 -04:00
Switch to general API nearly done.
This commit is contained in:
parent
a60d5556af
commit
d7f1c68366
13 changed files with 226 additions and 142 deletions
|
@ -3,6 +3,7 @@
|
||||||
position: fixed;
|
position: fixed;
|
||||||
z-index: 5;
|
z-index: 5;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
height: 18px;
|
||||||
left: 0;
|
left: 0;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
padding: 6px 0 8px 0;
|
padding: 6px 0 8px 0;
|
||||||
|
|
|
@ -20,6 +20,8 @@ modulejs.define('core/server', ['$', '_', 'config'], function ($, _, config) {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else if (server.backend === 'aai') {
|
||||||
|
return modulejs.require('core/server-request-mock-aai')(data, callback);
|
||||||
} else {
|
} else {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
@ -28,3 +30,126 @@ modulejs.define('core/server', ['$', '_', 'config'], function ($, _, config) {
|
||||||
|
|
||||||
return server;
|
return server;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
modulejs.define('core/server-request-mock-aai', ['$', '_', 'core/settings', 'core/format'], function ($, _, allsettings, format) {
|
||||||
|
|
||||||
|
var loadText = function (href) {
|
||||||
|
|
||||||
|
var deferred = $.Deferred();
|
||||||
|
|
||||||
|
$.ajax(href, {dataType: 'text'}).always(function (content) {
|
||||||
|
|
||||||
|
content = content.replace ? content : null;
|
||||||
|
deferred.resolve(content);
|
||||||
|
});
|
||||||
|
|
||||||
|
return deferred;
|
||||||
|
},
|
||||||
|
|
||||||
|
loadJson = function (href) {
|
||||||
|
|
||||||
|
var deferred = $.Deferred();
|
||||||
|
|
||||||
|
loadText(href).always(function (content) {
|
||||||
|
|
||||||
|
var json = content.replace ? JSON.parse(content.replace(/\/\*[\s\S]*?\*\/|\/\/.*?(\n|$)/g, '')) : {};
|
||||||
|
deferred.resolve(json);
|
||||||
|
});
|
||||||
|
|
||||||
|
return deferred;
|
||||||
|
},
|
||||||
|
|
||||||
|
parse = function (absHref, html) {
|
||||||
|
|
||||||
|
var id = '#data-apache-autoindex',
|
||||||
|
$html = $(html),
|
||||||
|
$id = $html.filter(id);
|
||||||
|
|
||||||
|
if (!$id.length) {
|
||||||
|
$id = $html.find(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _.compact(_.map($id.find('table').find('td').closest('tr'), function (tr) {
|
||||||
|
|
||||||
|
var $tds = $(tr).find('td'),
|
||||||
|
$a = $tds.eq(1).find('a');
|
||||||
|
|
||||||
|
return $a.text() === 'Parent Directory' ? null : {
|
||||||
|
absHref: absHref + $a.attr('href'),
|
||||||
|
time: format.parseDate($tds.eq(2).text(), ['YYYY-MM-DD HH:mm', 'DD-MMM-YYYY HH:mm']),
|
||||||
|
size: format.parseSize($tds.eq(3).text())
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
return function (data, callback) {
|
||||||
|
|
||||||
|
if (data.action === 'get' && data.l10n === true) {
|
||||||
|
|
||||||
|
var isoCodes = data.l10nCodes.split(':');
|
||||||
|
var isoCode = data.l10nCodes.split(':')[0];
|
||||||
|
loadJson(allsettings.h5aiAbsHref + 'conf/l10n/' + isoCode + '.json').done(function (json) {
|
||||||
|
|
||||||
|
var result = {code: 0, l10n: {}};
|
||||||
|
|
||||||
|
if (json) {
|
||||||
|
result.l10n[isoCode] = json;
|
||||||
|
}
|
||||||
|
callback(result);
|
||||||
|
});
|
||||||
|
|
||||||
|
} else if (data.action === 'get' && data.custom === true) {
|
||||||
|
|
||||||
|
$.when(
|
||||||
|
loadText('_h5ai.header.html'),
|
||||||
|
loadText('_h5ai.footer.html')
|
||||||
|
).done(function (header, footer) {
|
||||||
|
|
||||||
|
callback({
|
||||||
|
code: 0,
|
||||||
|
custom: {
|
||||||
|
header: header,
|
||||||
|
footer: footer
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
} else if (data.action === 'get' && data.entries === true) {
|
||||||
|
|
||||||
|
var absHref = data.entriesHref,
|
||||||
|
what = data.entriesWhat,
|
||||||
|
magicSequence = '=h5ai=',
|
||||||
|
reContentType = /^text\/html;h5ai=/;
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: absHref,
|
||||||
|
type: what === 0 ? 'HEAD' : 'GET',
|
||||||
|
complete: function (xhr) {
|
||||||
|
|
||||||
|
var entries = [],
|
||||||
|
status = xhr.status;
|
||||||
|
|
||||||
|
if (status === 200 && reContentType.test(xhr.getResponseHeader('Content-Type'))) {
|
||||||
|
status = magicSequence;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status === magicSequence && what > 0) {
|
||||||
|
entries = parse(absHref, xhr.responseText);
|
||||||
|
}
|
||||||
|
entries.push({absHref: absHref, status: status, content: what > 0});
|
||||||
|
|
||||||
|
callback({
|
||||||
|
code: 0,
|
||||||
|
entries: entries
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
|
@ -82,11 +82,6 @@ modulejs.define('ext/crumb', ['_', '$', 'core/settings', 'core/resource', 'core/
|
||||||
_.each(crumb, function (e) {
|
_.each(crumb, function (e) {
|
||||||
|
|
||||||
$ul.append(update(e));
|
$ul.append(update(e));
|
||||||
|
|
||||||
e.fetchStatus(function (e) {
|
|
||||||
|
|
||||||
update(e);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
event.sub('entry.created', onContentChanged);
|
event.sub('entry.created', onContentChanged);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('ext/custom', ['_', '$', 'core/settings'], function (_, $, allsettings) {
|
modulejs.define('ext/custom', ['_', '$', 'core/settings', 'core/server'], function (_, $, allsettings, server) {
|
||||||
|
|
||||||
var settings = _.extend({
|
var settings = _.extend({
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
@ -7,46 +7,23 @@ modulejs.define('ext/custom', ['_', '$', 'core/settings'], function (_, $, allse
|
||||||
footer: '_h5ai.footer.html'
|
footer: '_h5ai.footer.html'
|
||||||
}, allsettings.custom),
|
}, allsettings.custom),
|
||||||
|
|
||||||
getHtml = function (url, callback) {
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: url,
|
|
||||||
type: 'POST',
|
|
||||||
dataType: 'html',
|
|
||||||
success: function (html) {
|
|
||||||
|
|
||||||
callback(html);
|
|
||||||
},
|
|
||||||
error: function () {
|
|
||||||
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
init = function () {
|
init = function () {
|
||||||
|
|
||||||
if (!settings.enabled) {
|
if (!settings.enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_.isString(settings.header)) {
|
server.request({action: 'get', custom: true}, function (response) {
|
||||||
getHtml(settings.header, function (html) {
|
|
||||||
|
|
||||||
if (html) {
|
if (response) {
|
||||||
$('<div id="content-header">' + html + '</div>').prependTo('#content');
|
if (response.custom.header) {
|
||||||
|
$('<div id="content-header">' + response.custom.header + '</div>').prependTo('#content');
|
||||||
}
|
}
|
||||||
});
|
if (response.custom.footer) {
|
||||||
}
|
$('<div id="content-footer">' + response.custom.footer + '</div>').appendTo('#content');
|
||||||
|
|
||||||
if (_.isString(settings.footer)) {
|
|
||||||
getHtml(settings.footer, function (html) {
|
|
||||||
|
|
||||||
if (html) {
|
|
||||||
$('<div id="content-footer">' + html + '</div>').appendTo('#content');
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('ext/l10n', ['_', '$', 'core/settings', 'core/langs', 'core/format', 'core/store', 'core/event'], function (_, $, allsettings, langs, format, store, event) {
|
modulejs.define('ext/l10n', ['_', '$', 'core/settings', 'core/langs', 'core/format', 'core/store', 'core/event', 'core/server'], function (_, $, allsettings, langs, format, store, event, server) {
|
||||||
|
|
||||||
var settings = _.extend({
|
var settings = _.extend({
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
@ -72,19 +72,11 @@ modulejs.define('ext/l10n', ['_', '$', 'core/settings', 'core/langs', 'core/form
|
||||||
callback(loaded[isoCode]);
|
callback(loaded[isoCode]);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$.ajax({
|
server.request({action: 'get', l10n: true, l10nCodes: isoCode}, function (response) {
|
||||||
url: allsettings.h5aiAbsHref + 'conf/l10n/' + isoCode + '.json',
|
|
||||||
dataType: 'json',
|
|
||||||
success: function (json) {
|
|
||||||
|
|
||||||
loaded[isoCode] = _.extend({}, defaultTranslations, json, {isoCode: isoCode});
|
var json = response.l10n && response.l10n[isoCode] ? response.l10n[isoCode] : {};
|
||||||
callback(loaded[isoCode]);
|
loaded[isoCode] = _.extend({}, defaultTranslations, json, {isoCode: isoCode});
|
||||||
},
|
callback(loaded[isoCode]);
|
||||||
error: function () {
|
|
||||||
|
|
||||||
loaded[isoCode] = _.extend({}, defaultTranslations, {isoCode: isoCode});
|
|
||||||
callback(loaded[isoCode]);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/event', 'core/entry', 'core/parser'], function (_, $, allsettings, resource, event, entry, parser) {
|
modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/event', 'core/entry'], function (_, $, allsettings, resource, event, entry) {
|
||||||
|
|
||||||
var settings = _.extend({
|
var settings = _.extend({
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
@ -104,7 +104,7 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/e
|
||||||
return $html;
|
return $html;
|
||||||
},
|
},
|
||||||
|
|
||||||
createOnIndicatorClick = function (parser) {
|
createOnIndicatorClick = function () {
|
||||||
|
|
||||||
var $tree = $('#tree'),
|
var $tree = $('#tree'),
|
||||||
slide = function (entry, $indicator, $content, down) {
|
slide = function (entry, $indicator, $content, down) {
|
||||||
|
@ -127,7 +127,7 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/e
|
||||||
|
|
||||||
if ($indicator.hasClass('unknown')) {
|
if ($indicator.hasClass('unknown')) {
|
||||||
|
|
||||||
entry.fetchContent(parser, function (entry) {
|
entry.fetchContent(function (entry) {
|
||||||
|
|
||||||
entry.isContentVisible = false;
|
entry.isContentVisible = false;
|
||||||
|
|
||||||
|
@ -164,13 +164,13 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/e
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchTree = function (entry, parser, callback) {
|
fetchTree = function (entry, callback) {
|
||||||
|
|
||||||
entry.isContentVisible = true;
|
entry.isContentVisible = true;
|
||||||
entry.fetchContent(parser, function (entry) {
|
entry.fetchContent(function (entry) {
|
||||||
|
|
||||||
if (entry.parent) {
|
if (entry.parent) {
|
||||||
fetchTree(entry.parent, parser, callback);
|
fetchTree(entry.parent, callback);
|
||||||
} else {
|
} else {
|
||||||
callback(entry);
|
callback(entry);
|
||||||
}
|
}
|
||||||
|
@ -202,7 +202,7 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/e
|
||||||
},
|
},
|
||||||
|
|
||||||
// creates the complete tree from entry down to the root
|
// creates the complete tree from entry down to the root
|
||||||
init = function (entry, parser) {
|
init = function (entry) {
|
||||||
|
|
||||||
if (!settings.enabled) {
|
if (!settings.enabled) {
|
||||||
return;
|
return;
|
||||||
|
@ -211,7 +211,7 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/e
|
||||||
var $tree = $('<div id="tree"/>')
|
var $tree = $('<div id="tree"/>')
|
||||||
.appendTo('body')
|
.appendTo('body')
|
||||||
.scrollpanel()
|
.scrollpanel()
|
||||||
.on('click', '.indicator', createOnIndicatorClick(parser))
|
.on('click', '.indicator', createOnIndicatorClick())
|
||||||
.on('mouseenter', function () {
|
.on('mouseenter', function () {
|
||||||
|
|
||||||
shiftTree(true);
|
shiftTree(true);
|
||||||
|
@ -221,7 +221,7 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/e
|
||||||
shiftTree();
|
shiftTree();
|
||||||
});
|
});
|
||||||
|
|
||||||
fetchTree(entry, parser, function (root) {
|
fetchTree(entry, function (root) {
|
||||||
|
|
||||||
$tree
|
$tree
|
||||||
.find('.sp-container').append(update(root)).end()
|
.find('.sp-container').append(update(root)).end()
|
||||||
|
@ -243,5 +243,5 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/e
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
init(entry, parser);
|
init(entry);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/settings', 'core/location'], function ($, _, types, event, settings, location) {
|
modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/settings', 'core/location', 'core/server'], function ($, _, types, event, settings, location, server) {
|
||||||
|
|
||||||
var reEndsWithSlash = /\/$/,
|
var reEndsWithSlash = /\/$/,
|
||||||
|
|
||||||
|
@ -36,40 +36,6 @@ modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/sett
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
magicSequence = '=h5ai=',
|
|
||||||
reContentType = /^text\/html;h5ai=/,
|
|
||||||
getStatus = function (href, withContent, callback) {
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: href,
|
|
||||||
type: withContent ? 'GET' : 'HEAD',
|
|
||||||
complete: function (xhr) {
|
|
||||||
|
|
||||||
var res = {
|
|
||||||
status: xhr.status,
|
|
||||||
content: xhr.responseText
|
|
||||||
};
|
|
||||||
|
|
||||||
if (xhr.status === 200 && reContentType.test(xhr.getResponseHeader('Content-Type'))) {
|
|
||||||
res.status = magicSequence;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(res);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
ajaxRequest = function (self, parser, callback) {
|
|
||||||
|
|
||||||
getStatus(self.absHref, parser, function (response) {
|
|
||||||
|
|
||||||
self.status = response.status;
|
|
||||||
if (parser && response.status === magicSequence) {
|
|
||||||
parser.parse(self.absHref, response.content);
|
|
||||||
}
|
|
||||||
callback(self);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Cache
|
// Cache
|
||||||
|
@ -144,28 +110,38 @@ modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/sett
|
||||||
|
|
||||||
var self = getEntry(absHref);
|
var self = getEntry(absHref);
|
||||||
|
|
||||||
if (self.status || !self.isFolder()) {
|
if (self.status !== null) {
|
||||||
callback(self);
|
callback(self);
|
||||||
} else {
|
} else {
|
||||||
ajaxRequest(self, null, callback);
|
server.request({action: 'get', entries: true, entriesHref: self.absHref, entriesWhat: 0}, function (response) {
|
||||||
|
|
||||||
|
if (response.entries) {
|
||||||
|
_.each(response.entries, function (entry) {
|
||||||
|
getEntry(entry.absHref, entry.time, entry.size, entry.status, entry.content);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(self);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchContent = function (absHref, parser, callback) {
|
fetchContent = function (absHref, callback) {
|
||||||
|
|
||||||
var self = getEntry(absHref);
|
var self = getEntry(absHref);
|
||||||
|
|
||||||
if (self.isContentFetched) {
|
if (self.isContentFetched) {
|
||||||
callback(self);
|
callback(self);
|
||||||
} else {
|
} else {
|
||||||
fetchStatus(absHref, function (self) {
|
server.request({action: 'get', entries: true, entriesHref: self.absHref, entriesWhat: 1}, function (response) {
|
||||||
|
|
||||||
self.isContentFetched = true;
|
if (response.entries) {
|
||||||
if (self.status === magicSequence) {
|
_.each(response.entries, function (entry) {
|
||||||
ajaxRequest(self, parser, callback);
|
getEntry(entry.absHref, entry.time, entry.size, entry.status, entry.content);
|
||||||
} else {
|
});
|
||||||
callback(self);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
callback(self);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -245,9 +221,9 @@ modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/sett
|
||||||
return fetchStatus(this.absHref, callback);
|
return fetchStatus(this.absHref, callback);
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchContent: function (parser, callback) {
|
fetchContent: function (callback) {
|
||||||
|
|
||||||
return fetchContent(this.absHref, parser, callback);
|
return fetchContent(this.absHref, callback);
|
||||||
},
|
},
|
||||||
|
|
||||||
getCrumb: function () {
|
getCrumb: function () {
|
||||||
|
|
|
@ -112,10 +112,8 @@ modulejs.define('view/extended', ['_', '$', 'core/settings', 'core/resource', 'c
|
||||||
|
|
||||||
$ul.append(update(e));
|
$ul.append(update(e));
|
||||||
|
|
||||||
e.fetchStatus(function (e) {
|
// needed by aai
|
||||||
|
e.fetchStatus(function (e) { update(e); });
|
||||||
update(e);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$extended.append($ul);
|
$extended.append($ul);
|
||||||
|
|
|
@ -29,15 +29,6 @@
|
||||||
|
|
||||||
appHref = src.substr(0, src.length - filename.length),
|
appHref = src.substr(0, src.length - filename.length),
|
||||||
|
|
||||||
loadCommentedJson = function (href, callback) {
|
|
||||||
|
|
||||||
$.ajax(href, {dataType: 'text'}).always(function (response) {
|
|
||||||
|
|
||||||
var json = response.replace ? JSON.parse(response.replace(/\/\*[\s\S]*?\*\/|\/\/.*?(\n|$)/g, '')) : {};
|
|
||||||
callback(json);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
run = function (config) {
|
run = function (config) {
|
||||||
/*global amplify, Base64, jQuery, Modernizr, moment, _ */
|
/*global amplify, Base64, jQuery, Modernizr, moment, _ */
|
||||||
|
|
||||||
|
@ -66,22 +57,35 @@
|
||||||
|
|
||||||
} else if (backend === 'aai') {
|
} else if (backend === 'aai') {
|
||||||
|
|
||||||
loadCommentedJson(appHref + 'conf/options.json', function (options) {
|
var loadJson = function (href) {
|
||||||
loadCommentedJson(appHref + 'conf/types.json', function (types) {
|
|
||||||
loadCommentedJson(appHref + 'conf/langs.json', function (langs) {
|
|
||||||
|
|
||||||
run({
|
var deferred = $.Deferred();
|
||||||
options: options,
|
|
||||||
types: types,
|
$.ajax(href, {dataType: 'text'}).always(function (content) {
|
||||||
langs: langs,
|
|
||||||
server: {
|
var json = content.replace ? JSON.parse(content.replace(/\/\*[\s\S]*?\*\/|\/\/.*?(\n|$)/g, '')) : {};
|
||||||
backend: backend,
|
deferred.resolve(json);
|
||||||
api: false,
|
|
||||||
name: 'apache',
|
|
||||||
version: null
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return deferred;
|
||||||
|
};
|
||||||
|
|
||||||
|
$.when(
|
||||||
|
loadJson(appHref + 'conf/options.json'),
|
||||||
|
loadJson(appHref + 'conf/types.json'),
|
||||||
|
loadJson(appHref + 'conf/langs.json')
|
||||||
|
).done(function (options, types, langs) {
|
||||||
|
|
||||||
|
run({
|
||||||
|
options: options,
|
||||||
|
types: types,
|
||||||
|
langs: langs,
|
||||||
|
server: {
|
||||||
|
backend: backend,
|
||||||
|
api: false,
|
||||||
|
name: 'apache',
|
||||||
|
version: null
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ class Api {
|
||||||
if (array_key_exists("l10n", $_REQUEST)) {
|
if (array_key_exists("l10n", $_REQUEST)) {
|
||||||
|
|
||||||
list($iso_codes) = use_request_params("l10nCodes", "l10n");
|
list($iso_codes) = use_request_params("l10nCodes", "l10n");
|
||||||
$iso_codes = explode(",", $iso_codes);
|
$iso_codes = explode(":", $iso_codes);
|
||||||
$response["l10n"] = $this->app->get_l10n($iso_codes);
|
$response["l10n"] = $this->app->get_l10n($iso_codes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,14 +58,14 @@ class Api {
|
||||||
|
|
||||||
if (array_key_exists("custom", $_REQUEST)) {
|
if (array_key_exists("custom", $_REQUEST)) {
|
||||||
|
|
||||||
list($abs_href) = use_request_params("customHref", "custom");
|
list($abs_href) = use_optional_request_params("customHref", "custom");
|
||||||
$response["custom"] = $this->app->get_customizations($abs_href);
|
$response["custom"] = $this->app->get_customizations($abs_href);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists("entries", $_REQUEST)) {
|
if (array_key_exists("entries", $_REQUEST)) {
|
||||||
|
|
||||||
list($abs_href, $what) = use_request_params("entriesHref", "entriesWhat", "entries");
|
list($abs_href, $what) = use_optional_request_params("entriesHref", "entriesWhat", "entries");
|
||||||
$what = intval($what, 10);
|
$what = is_numeric($what) ? intval($what, 10) : 1;
|
||||||
$response["entries"] = $this->app->get_entries($abs_href, $what);
|
$response["entries"] = $this->app->get_entries($abs_href, $what);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -197,11 +197,11 @@ class App {
|
||||||
$html = "<table>";
|
$html = "<table>";
|
||||||
$html .= "<tr><th></th><th><span>Name</span></th><th><span>Last modified</span></th><th><span>Size</span></th></tr>";
|
$html .= "<tr><th></th><th><span>Name</span></th><th><span>Last modified</span></th><th><span>Size</span></th></tr>";
|
||||||
if ($folder->get_parent($cache)) {
|
if ($folder->get_parent($cache)) {
|
||||||
$html .= "<tr><td>UP</td><td><a href=\"..\">Parent Directory</a></td><td></td><td></td></tr>";
|
$html .= "<tr><td><img src=\"" . $this->app_abs_href . "client/icons/16x16/folder-parent.png\"/></td><td><a href=\"..\">Parent Directory</a></td><td></td><td></td></tr>";
|
||||||
}
|
}
|
||||||
foreach ($entries as $entry) {
|
foreach ($entries as $entry) {
|
||||||
$html .= "<tr>";
|
$html .= "<tr>";
|
||||||
$html .= "<td>" . ($entry->is_folder ? "DIR" : "FILE") . "</td>";
|
$html .= "<td><img src=\"" . $this->app_abs_href . "client/icons/16x16/" . ($entry->is_folder ? "folder" : "default") . ".png\"/></td>";
|
||||||
$html .= "<td><a href=\"" . $entry->abs_href . "\">" . basename($entry->abs_path) . "</a></td>";
|
$html .= "<td><a href=\"" . $entry->abs_href . "\">" . basename($entry->abs_path) . "</a></td>";
|
||||||
$html .= "<td>" . date("Y-m-d H:i", $entry->date) . "</td>";
|
$html .= "<td>" . date("Y-m-d H:i", $entry->date) . "</td>";
|
||||||
$html .= "<td>" . ($entry->size !== null ? intval($entry->size / 1000) . " KB" : "" ) . "</td>";
|
$html .= "<td>" . ($entry->size !== null ? intval($entry->size / 1000) . " KB" : "" ) . "</td>";
|
||||||
|
|
|
@ -23,7 +23,7 @@ $app = new App(APP_ABS_PATH, APP_ABS_HREF, ABS_HREF);
|
||||||
|
|
||||||
if (count($_REQUEST)) {
|
if (count($_REQUEST)) {
|
||||||
|
|
||||||
header("Content-type: application/json;h5ai={{pkg.version}}");
|
header("Content-type: application/json");
|
||||||
|
|
||||||
normalized_require_once("/server/php/inc/Api.php");
|
normalized_require_once("/server/php/inc/Api.php");
|
||||||
$api = new Api($app);
|
$api = new Api($app);
|
||||||
|
@ -33,8 +33,6 @@ if (count($_REQUEST)) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
header("Content-type: text/html;h5ai={{pkg.version}}");
|
|
||||||
|
|
||||||
$HREF = $app->get_app_abs_href();
|
$HREF = $app->get_app_abs_href();
|
||||||
$JSON = $app->get_generic_json();
|
$JSON = $app->get_generic_json();
|
||||||
$FALLBACK = $app->get_no_js_fallback();
|
$FALLBACK = $app->get_no_js_fallback();
|
||||||
|
|
|
@ -30,6 +30,24 @@ function use_request_params($keys) {
|
||||||
return $values;
|
return $values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function use_optional_request_params($keys) {
|
||||||
|
|
||||||
|
if (!is_array($keys)) {
|
||||||
|
$keys = func_get_args();
|
||||||
|
}
|
||||||
|
|
||||||
|
$values = array();
|
||||||
|
foreach ($keys as $key) {
|
||||||
|
if (array_key_exists($key, $_REQUEST)) {
|
||||||
|
$values[] = $_REQUEST[$key];
|
||||||
|
unset($_REQUEST[$key]);
|
||||||
|
} else {
|
||||||
|
$values[] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $values;
|
||||||
|
}
|
||||||
|
|
||||||
function delete_tempfile($file) {
|
function delete_tempfile($file) {
|
||||||
|
|
||||||
@unlink($file);
|
@unlink($file);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue