Add image upload UI and server-side upload/list APIs

This commit is contained in:
dsyoon
2025-12-27 16:05:06 +09:00
parent 72d0eafd9e
commit dafeaa7c44
6 changed files with 424 additions and 43 deletions

View File

@@ -42,8 +42,8 @@ function onLoad() {
exemptionSelector: '.selected'
});
// Initialize Advanced Galleriffic Gallery
$('#thumbs').galleriffic({
// Initialize Advanced Galleriffic Gallery (store instance for uploader)
window.dreamgirlGallery = $('#thumbs').galleriffic({
delay: 2500,
numThumbs: 15,
preloadAhead: 10,
@@ -96,10 +96,20 @@ function onLoad() {
text += "</li>";
}
text += "</ul>";
$("#thumbs").html(text);
$("#thumbs-list").html(text);
initGallery();
}
function tryLoadFromLocalListApi() {
return $.ajax({
url: 'api/list_images.php',
type: 'GET',
dataType: 'json',
cache: false,
timeout: 8000
});
}
function fallbackToLocalManifest() {
if (window.DREAMGIRL_IMAGES && window.DREAMGIRL_IMAGES.length) {
buildThumbsFromList(window.DREAMGIRL_IMAGES);
@@ -110,33 +120,44 @@ function onLoad() {
return true;
}
$.ajax({
url : getApiUrl(),
type: 'GET',
data : "id=user",
dataType : "jsonp",
jsonp : "callback",
cache : false,
timeout: 15000,
success: function(data) {
try {
var filelist = data && data.filelist ? data.filelist : null;
if (!filelist || !filelist.length) return fallbackToLocalManifest();
var names = [];
for (var i=0; i<filelist.length; i++) {
if (filelist[i] && filelist[i]["img"]) names.push(filelist[i]["img"]);
}
if (!names.length) return fallbackToLocalManifest();
buildThumbsFromList(names);
} catch (e) {
// Prefer same-origin dynamic list (so newly uploaded images appear on refresh).
tryLoadFromLocalListApi()
.done(function(resp) {
if (resp && resp.ok && resp.images && resp.images.length) {
buildThumbsFromList(resp.images);
} else {
fallbackToLocalManifest();
}
},
error: function () {
// If remote API fails (common on HTTPS if api host doesn't support it), fall back to local images.
fallbackToLocalManifest();
}
});
})
.fail(function() {
// If local list API is unavailable, try remote JSONP API, then fall back to static manifest.
$.ajax({
url : getApiUrl(),
type: 'GET',
data : "id=user",
dataType : "jsonp",
jsonp : "callback",
cache : false,
timeout: 15000,
success: function(data) {
try {
var filelist = data && data.filelist ? data.filelist : null;
if (!filelist || !filelist.length) return fallbackToLocalManifest();
var names = [];
for (var i=0; i<filelist.length; i++) {
if (filelist[i] && filelist[i]["img"]) names.push(filelist[i]["img"]);
}
if (!names.length) return fallbackToLocalManifest();
buildThumbsFromList(names);
} catch (e) {
fallbackToLocalManifest();
}
},
error: function () {
fallbackToLocalManifest();
}
});
});
return true;
}