mirror of
https://github.com/Starlio-app/Starlio-web.git
synced 2024-12-25 17:53:47 +03:00
gallery made
This commit is contained in:
parent
f6cfc84856
commit
ad74948bd2
3 changed files with 143 additions and 15 deletions
1
main.go
1
main.go
|
@ -35,6 +35,7 @@ func main() {
|
|||
router.HandleFunc("/api/get/settings", controllers.SettingsGet).Methods("GET")
|
||||
router.HandleFunc("/api/get/version", controllers.Version).Methods("GET")
|
||||
router.HandleFunc("/api/update/settings", controllers.SettingsUpdate).Methods("POST")
|
||||
router.HandleFunc("/api/update/wallpaper", controllers.WallpaperUpdate).Methods("POST")
|
||||
|
||||
go func() {
|
||||
err := http.ListenAndServe(":8080", router)
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
<meta charset="UTF-8">
|
||||
<title>EveryNasa</title>
|
||||
<link rel="icon" href="/static/image/icons/favicon.png">
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="/static/style/gallery.css" type="text/css">
|
||||
</head>
|
||||
<body style="background: #131313; color: white;">
|
||||
|
@ -32,12 +31,36 @@
|
|||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<div class="modal fade" id="WallpaperModal" aria-hidden="true" aria-labelledby="WallpaperModal" tabindex="-1" style="color: black;">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="WallpaperModale"></h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body"></div>
|
||||
<div class="modal-footer">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container">
|
||||
<header class="header-row">
|
||||
</header>
|
||||
</div>
|
||||
|
||||
<div class="toast-container position-fixed bottom-0 end-0 p-3">
|
||||
<div id="liveToast" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
|
||||
<div class="toast-header">
|
||||
<img src="/static/image/icons/favicon.png" class="rounded me-2" alt="EveryNasa" width="30">
|
||||
<strong class="me-auto" style="color: black;">EveryNasa</strong>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="toast-body" style="color: black;"></div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.min.js" integrity="sha384-ODmDIVzN+pFdexxHEHFBQH3/9/vQ9uori45z4JjnFsRydbmQbmL5t1tQ0culUzyK" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/js/bootstrap.min.js" integrity="sha384-7VPbUDkoPSGFnVtYi0QogXtr74QeVeeIs99Qfg5YCF+TidwNdjvaKZX19NZ/e6oz" crossorigin="anonymous"></script>
|
||||
<script src="/static/scripts/gallery.js" type="application/javascript"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,17 +1,121 @@
|
|||
$.ajax({
|
||||
url: `https://api.nasa.gov/planetary/apod?api_key=1gI9G84ZafKDEnrbydviGknReOGiVK9jqrQBE3et&start_date=${new Date().toLocaleString().slice(6, 10)}-${new Date().toLocaleString().slice(3, 5)}-01&end_date=${new Date().toLocaleString().slice(6,10)}-${new Date().toLocaleString().slice(3, 5)}-${new Date().toLocaleString().slice(3, 5)}`,
|
||||
url: `https://api.nasa.gov/planetary/apod?api_key=1gI9G84ZafKDEnrbydviGknReOGiVK9jqrQBE3et&start_date=${new Date().toLocaleString().slice(6, 10)}-${new Date().toLocaleString().slice(3, 5)}-01&end_date=${new Date().toLocaleString().slice(6,10)}-${new Date().toLocaleString().slice(3, 5)}-${new Date().toLocaleString().slice(0,2)}`,
|
||||
type: "GET",
|
||||
success: function(data){
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
if (data[i].media_type == "image") {
|
||||
$(".header-row").append(`
|
||||
<span>
|
||||
<div class="card">
|
||||
<img src="${data[i].url}" alt="${data[i].title}" class="card-img-top">
|
||||
</div>
|
||||
</span>
|
||||
`)
|
||||
Wallpaper(data)
|
||||
},
|
||||
error: function(){
|
||||
let prev_date = Number(new Date().toLocaleString().slice(0,2))
|
||||
this.url = `https://api.nasa.gov/planetary/apod?api_key=1gI9G84ZafKDEnrbydviGknReOGiVK9jqrQBE3et&start_date=${new Date().toLocaleString().slice(6, 10)}-${new Date().toLocaleString().slice(3, 5)}-01&end_date=${new Date().toLocaleString().slice(6,10)}-${new Date().toLocaleString().slice(3, 5)}-${prev_date-1}`,
|
||||
$.ajax({
|
||||
url: this.url,
|
||||
type: "GET",
|
||||
success: function(data){
|
||||
Wallpaper(data)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const myModal = new bootstrap.Modal('#Wallpaper', {
|
||||
keyboard: false
|
||||
})
|
||||
myModal.show()
|
||||
|
||||
function Wallpaper(data) {
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
if (data[i].media_type === "image") {
|
||||
$(".header-row").append(`
|
||||
<div class="card">
|
||||
<a data-bs-toggle="modal" href="#WallpaperModal" role="button">
|
||||
<img src="${data[i].url}" alt="${data[i].title}" class="card-img-top" idi="${i+1}">
|
||||
</a>
|
||||
</div>
|
||||
`)
|
||||
} else {
|
||||
$(".header-row").append(`
|
||||
<div class="card">
|
||||
<a data-bs-toggle="modal" href="#WallpaperModal" role="button">
|
||||
<img src="https://img.youtube.com/vi/${data[i].url.slice(30,41)}/maxresdefault.jpg" alt="${data[i].title}" class="card-img-top" idi="${i+1}">
|
||||
</a>
|
||||
</div>
|
||||
`)
|
||||
}
|
||||
let buttons = document.querySelector(".header-row")
|
||||
buttons.addEventListener("click", function (event) {
|
||||
if (event.target.tagName === "IMG") {
|
||||
let id = event.target.getAttribute("idi")
|
||||
let img = document.querySelector(".modal-body")
|
||||
let title = document.querySelector(".modal-title")
|
||||
|
||||
let button = document.querySelector(".modal-footer")
|
||||
button.innerHTML = `
|
||||
<button type="button" class="btn btn-primary" id="setWallpaper">Set Wallpaper</button>
|
||||
`
|
||||
let setWallpaper = document.querySelector("#setWallpaper")
|
||||
|
||||
if(data[id-1].media_type === "image") {
|
||||
img.innerHTML = `
|
||||
<img src="${data[id - 1].url}" alt="${data[id - 1].title}" class="card-img-top">
|
||||
<p>Author: <strong>${data[id - 1].copyright}</strong></p>
|
||||
<p>Date of shooting: <strong>${data[id - 1].date}</strong></p>
|
||||
<p>Explanation: <strong>${data[id - 1].explanation}</strong></p>
|
||||
`
|
||||
title.innerHTML = `
|
||||
<h5 class="modal-title">${data[id - 1].title}</h5>
|
||||
`
|
||||
|
||||
setWallpaper.addEventListener("click", function () {
|
||||
$.ajax({
|
||||
url: `http://localhost:8080/api/update/wallpaper`,
|
||||
type: "POST",
|
||||
data: {
|
||||
url: data[id - 1].hdurl
|
||||
},
|
||||
success: function () {
|
||||
$(".toast-body").text("The wallpaper has been installed")
|
||||
let toastLiveExample = document.getElementById('liveToast')
|
||||
let toast = new bootstrap.Toast(toastLiveExample)
|
||||
toast.show()
|
||||
},
|
||||
error: function (err) {
|
||||
console.error(err);
|
||||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
img.innerHTML = `
|
||||
<iframe width="460" height="315" src="${data[id - 1].url}" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
|
||||
<p>Author: <strong>${data[id - 1].copyright}</strong></p>
|
||||
<p>Date of shooting: <strong>${data[id - 1].date}</strong></p>
|
||||
<p>Explanation: <strong>${data[id - 1].explanation}</strong></p>
|
||||
`
|
||||
title.innerHTML = `
|
||||
<h5 class="modal-title">${data[id].title}</h5>
|
||||
`
|
||||
|
||||
setWallpaper.addEventListener("click", function () {
|
||||
console.log(`https://img.youtube.com/vi/${data[id - 1].url.slice(30,41)}/maxresdefault.jpg`);
|
||||
|
||||
$.ajax({
|
||||
url: `http://localhost:8080/api/update/wallpaper`,
|
||||
type: "POST",
|
||||
data: {
|
||||
url: `https://img.youtube.com/vi/${data[id - 1].url.slice(30,41)}/maxresdefault.jpg`
|
||||
},
|
||||
success: function () {
|
||||
$(".toast-body").text("The wallpaper has been installed")
|
||||
let toastLiveExample = document.getElementById('liveToast')
|
||||
let toast = new bootstrap.Toast(toastLiveExample)
|
||||
toast.show()
|
||||
},
|
||||
error: function (err) {
|
||||
console.error(err);
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue