1
0
Fork 0
mirror of https://github.com/Luzifer/share.git synced 2024-10-18 13:24:23 +00:00
share/frontend/app.js

77 lines
1.8 KiB
JavaScript
Raw Normal View History

2017-12-02 15:10:19 +00:00
// Generated by CoffeeScript 1.12.4
(function() {
var MSG_GENERIC_ERR, MSG_NOT_FOUND, MSG_NOT_PERMITTED, embedFileInfo, fileURL, handleEmbed, handleError, handleErrorMessage, hashLoad;
2017-12-02 15:10:19 +00:00
fileURL = void 0;
MSG_NOT_FOUND = 'File not found';
MSG_NOT_PERMITTED = 'Not allowed to access file';
MSG_GENERIC_ERR = 'Something went wrong';
2017-12-02 15:10:19 +00:00
$(function() {
$(window).bind('hashchange', hashLoad);
return hashLoad();
});
hashLoad = function() {
var file;
file = window.location.hash.substring(1);
return embedFileInfo(file);
};
embedFileInfo = function(file) {
if (file === '') {
return handleErrorMessage(MSG_NOT_FOUND);
}
2017-12-02 15:10:19 +00:00
fileURL = file;
return $.ajax(file, {
method: 'HEAD',
success: handleEmbed,
error: handleError
2017-12-02 15:10:19 +00:00
});
};
handleEmbed = function(data, status, xhr) {
var type;
type = xhr.getResponseHeader('Content-Type');
console.log(fileURL);
$('.show-loading').hide();
$('.filelink-href').attr('href', fileURL);
$('.filelink-src').attr('src', fileURL);
$('.filename').text(fileURL.substring(fileURL.lastIndexOf('/') + 1));
if (type.match(/^image\//)) {
$('.show-image').show();
return;
}
if (type.match(/^video\//)) {
$('.show-video').show();
return;
}
return $('.show-generic').show();
};
handleError = function(xhr, status) {
var message;
message = (function() {
switch (xhr.status) {
case 404:
return MSG_NOT_FOUND;
case 403:
return MSG_NOT_PERMITTED;
default:
return MSG_GENERIC_ERR;
}
})();
return handleErrorMessage(message);
};
handleErrorMessage = function(message) {
$('.error').text(message);
$('.show-loading').hide();
return $('.show-error').show();
};
2017-12-02 15:10:19 +00:00
}).call(this);