Implemented music page
This commit is contained in:
parent
c32166f38c
commit
50cd062140
@ -1,19 +0,0 @@
|
|||||||
package auth
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"io/ioutil"
|
|
||||||
|
|
||||||
"github.com/animenotifier/arn"
|
|
||||||
)
|
|
||||||
|
|
||||||
var apiKeys arn.APIKeys
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
data, _ := ioutil.ReadFile("security/api-keys.json")
|
|
||||||
err := json.Unmarshal(data, &apiKeys)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
@ -29,8 +29,8 @@ type GoogleUser struct {
|
|||||||
// InstallGoogleAuth enables Google login for the app.
|
// InstallGoogleAuth enables Google login for the app.
|
||||||
func InstallGoogleAuth(app *aero.Application) {
|
func InstallGoogleAuth(app *aero.Application) {
|
||||||
config := &oauth2.Config{
|
config := &oauth2.Config{
|
||||||
ClientID: apiKeys.Google.ID,
|
ClientID: arn.APIKeys.Google.ID,
|
||||||
ClientSecret: apiKeys.Google.Secret,
|
ClientSecret: arn.APIKeys.Google.Secret,
|
||||||
RedirectURL: "https://" + app.Config.Domain + "/auth/google/callback",
|
RedirectURL: "https://" + app.Config.Domain + "/auth/google/callback",
|
||||||
Scopes: []string{
|
Scopes: []string{
|
||||||
"https://www.googleapis.com/auth/userinfo.email",
|
"https://www.googleapis.com/auth/userinfo.email",
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
@ -21,30 +17,8 @@ var discord *discordgo.Session
|
|||||||
func main() {
|
func main() {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
exe, err := os.Executable()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
dir := path.Dir(exe)
|
|
||||||
var apiKeysPath string
|
|
||||||
apiKeysPath, err = filepath.Abs(dir + "/../../security/api-keys.json")
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var apiKeys arn.APIKeys
|
|
||||||
data, _ := ioutil.ReadFile(apiKeysPath)
|
|
||||||
err = json.Unmarshal(data, &apiKeys)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
discord, _ = discordgo.New()
|
discord, _ = discordgo.New()
|
||||||
discord.Token = "Bot " + apiKeys.Discord.Token
|
discord.Token = "Bot " + arn.APIKeys.Discord.Token
|
||||||
|
|
||||||
// Verify a Token was provided
|
// Verify a Token was provided
|
||||||
if discord.Token == "" {
|
if discord.Token == "" {
|
||||||
|
@ -46,9 +46,15 @@ func sync(data *kitsu.Anime) {
|
|||||||
anime.EpisodeCount = attr.EpisodeCount
|
anime.EpisodeCount = attr.EpisodeCount
|
||||||
anime.EpisodeLength = attr.EpisodeLength
|
anime.EpisodeLength = attr.EpisodeLength
|
||||||
anime.Status = attr.Status
|
anime.Status = attr.Status
|
||||||
anime.NSFW = attr.Nsfw
|
|
||||||
anime.Summary = arn.FixAnimeDescription(attr.Synopsis)
|
anime.Summary = arn.FixAnimeDescription(attr.Synopsis)
|
||||||
|
|
||||||
|
// NSFW
|
||||||
|
if attr.Nsfw {
|
||||||
|
anime.NSFW = 1
|
||||||
|
} else {
|
||||||
|
anime.NSFW = 0
|
||||||
|
}
|
||||||
|
|
||||||
// Rating
|
// Rating
|
||||||
overall, convertError := strconv.ParseFloat(attr.AverageRating, 64)
|
overall, convertError := strconv.ParseFloat(attr.AverageRating, 64)
|
||||||
|
|
||||||
@ -59,10 +65,10 @@ func sync(data *kitsu.Anime) {
|
|||||||
anime.Rating.Overall = overall
|
anime.Rating.Overall = overall
|
||||||
|
|
||||||
// Trailers
|
// Trailers
|
||||||
anime.Trailers = []arn.ExternalMedia{}
|
anime.Trailers = []*arn.ExternalMedia{}
|
||||||
|
|
||||||
if attr.YoutubeVideoID != "" {
|
if attr.YoutubeVideoID != "" {
|
||||||
anime.Trailers = append(anime.Trailers, arn.ExternalMedia{
|
anime.Trailers = append(anime.Trailers, &arn.ExternalMedia{
|
||||||
Service: "Youtube",
|
Service: "Youtube",
|
||||||
ServiceID: attr.YoutubeVideoID,
|
ServiceID: attr.YoutubeVideoID,
|
||||||
})
|
})
|
||||||
|
@ -2,7 +2,6 @@ package middleware
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -15,17 +14,6 @@ import (
|
|||||||
"github.com/parnurzeal/gorequest"
|
"github.com/parnurzeal/gorequest"
|
||||||
)
|
)
|
||||||
|
|
||||||
var apiKeys arn.APIKeys
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
data, _ := ioutil.ReadFile("security/api-keys.json")
|
|
||||||
err := json.Unmarshal(data, &apiKeys)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// UserInfo updates user related information after each request.
|
// UserInfo updates user related information after each request.
|
||||||
func UserInfo() aero.Middleware {
|
func UserInfo() aero.Middleware {
|
||||||
return func(ctx *aero.Context, next func()) {
|
return func(ctx *aero.Context, next func()) {
|
||||||
@ -84,7 +72,7 @@ func updateUserInfo(ctx *aero.Context, user *arn.User) {
|
|||||||
// Updates the location of the user.
|
// Updates the location of the user.
|
||||||
func updateUserLocation(user *arn.User, newIP string) {
|
func updateUserLocation(user *arn.User, newIP string) {
|
||||||
user.IP = newIP
|
user.IP = newIP
|
||||||
locationAPI := "https://api.ipinfodb.com/v3/ip-city/?key=" + apiKeys.IPInfoDB.ID + "&ip=" + user.IP + "&format=json"
|
locationAPI := "https://api.ipinfodb.com/v3/ip-city/?key=" + arn.APIKeys.IPInfoDB.ID + "&ip=" + user.IP + "&format=json"
|
||||||
|
|
||||||
response, data, err := gorequest.New().Get(locationAPI).EndBytes()
|
response, data, err := gorequest.New().Get(locationAPI).EndBytes()
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package music
|
package music
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/aerogo/aero"
|
"github.com/aerogo/aero"
|
||||||
@ -12,105 +13,19 @@ const maxTracks = 10
|
|||||||
|
|
||||||
// Get renders the music page.
|
// Get renders the music page.
|
||||||
func Get(ctx *aero.Context) string {
|
func Get(ctx *aero.Context) string {
|
||||||
tracks := []*arn.SoundTrack{}
|
tracks, err := arn.AllSoundTracks()
|
||||||
|
|
||||||
tracks = append(tracks, &arn.SoundTrack{
|
if err != nil {
|
||||||
ID: arn.GenerateID("SoundTrack"),
|
return ctx.Error(http.StatusInternalServerError, "Error fetching soundtracks", err)
|
||||||
Media: []arn.ExternalMedia{
|
|
||||||
arn.ExternalMedia{
|
|
||||||
Service: "Soundcloud",
|
|
||||||
ServiceID: "145918628",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Tags: []string{
|
|
||||||
"anime:2357",
|
|
||||||
},
|
|
||||||
Created: arn.DateTimeUTC(),
|
|
||||||
CreatedBy: "4J6qpK1ve",
|
|
||||||
})
|
|
||||||
|
|
||||||
tracks = append(tracks, &arn.SoundTrack{
|
|
||||||
ID: arn.GenerateID("SoundTrack"),
|
|
||||||
Media: []arn.ExternalMedia{
|
|
||||||
arn.ExternalMedia{
|
|
||||||
Service: "Soundcloud",
|
|
||||||
ServiceID: "127672476",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Tags: []string{
|
|
||||||
"anime:7622",
|
|
||||||
},
|
|
||||||
Created: arn.DateTimeUTC(),
|
|
||||||
CreatedBy: "4J6qpK1ve",
|
|
||||||
})
|
|
||||||
|
|
||||||
tracks = append(tracks, &arn.SoundTrack{
|
|
||||||
ID: arn.GenerateID("SoundTrack"),
|
|
||||||
Media: []arn.ExternalMedia{
|
|
||||||
arn.ExternalMedia{
|
|
||||||
Service: "Soundcloud",
|
|
||||||
ServiceID: "270777538",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Tags: []string{
|
|
||||||
"anime:11469",
|
|
||||||
},
|
|
||||||
Created: arn.DateTimeUTC(),
|
|
||||||
CreatedBy: "4J6qpK1ve",
|
|
||||||
})
|
|
||||||
|
|
||||||
tracks = append(tracks, &arn.SoundTrack{
|
|
||||||
ID: arn.GenerateID("SoundTrack"),
|
|
||||||
Media: []arn.ExternalMedia{
|
|
||||||
arn.ExternalMedia{
|
|
||||||
Service: "Soundcloud",
|
|
||||||
ServiceID: "243839100",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Tags: []string{
|
|
||||||
"anime:9962",
|
|
||||||
},
|
|
||||||
Created: arn.DateTimeUTC(),
|
|
||||||
CreatedBy: "4J6qpK1ve",
|
|
||||||
})
|
|
||||||
|
|
||||||
tracks = append(tracks, &arn.SoundTrack{
|
|
||||||
ID: arn.GenerateID("SoundTrack"),
|
|
||||||
Media: []arn.ExternalMedia{
|
|
||||||
arn.ExternalMedia{
|
|
||||||
Service: "Soundcloud",
|
|
||||||
ServiceID: "207355237",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Tags: []string{
|
|
||||||
"anime:6589",
|
|
||||||
},
|
|
||||||
Created: arn.DateTimeUTC(),
|
|
||||||
CreatedBy: "4J6qpK1ve",
|
|
||||||
})
|
|
||||||
|
|
||||||
tracks = append(tracks, &arn.SoundTrack{
|
|
||||||
ID: arn.GenerateID("SoundTrack"),
|
|
||||||
Media: []arn.ExternalMedia{
|
|
||||||
arn.ExternalMedia{
|
|
||||||
Service: "Soundcloud",
|
|
||||||
ServiceID: "242172944",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Tags: []string{
|
|
||||||
"anime:10740",
|
|
||||||
},
|
|
||||||
Created: arn.DateTimeUTC(),
|
|
||||||
CreatedBy: "4J6qpK1ve",
|
|
||||||
})
|
|
||||||
|
|
||||||
if len(tracks) > maxTracks {
|
|
||||||
tracks = tracks[:maxTracks]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(tracks, func(i, j int) bool {
|
sort.Slice(tracks, func(i, j int) bool {
|
||||||
return tracks[i].Created > tracks[j].Created
|
return tracks[i].Created > tracks[j].Created
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if len(tracks) > maxTracks {
|
||||||
|
tracks = tracks[:maxTracks]
|
||||||
|
}
|
||||||
|
|
||||||
return ctx.HTML(components.Music(tracks))
|
return ctx.HTML(components.Music(tracks))
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
component NewSoundTrack(user *arn.User)
|
component NewSoundTrack(user *arn.User)
|
||||||
.widgets
|
.widgets
|
||||||
.widget
|
.widget
|
||||||
input#soundcloud-link.widget-element(type="text", placeholder="Soundcloud link or ID")
|
input#soundcloud-link.widget-element(type="text", placeholder="Soundcloud link")
|
||||||
input#anime-link.widget-element(type="text", placeholder="Anime link or ID")
|
input#anime-link.widget-element(type="text", placeholder="Anime link")
|
||||||
input#osu-link.widget-element(type="text", placeholder="Osu beatmap link (optional)")
|
input#osu-link.widget-element(type="text", placeholder="Osu beatmap link (optional)")
|
||||||
|
|
||||||
button.action(data-action="createSoundTrack", data-trigger="click")
|
button.action(data-action="createSoundTrack", data-trigger="click")
|
||||||
|
@ -103,6 +103,28 @@ export function createThread(arn: AnimeNotifier) {
|
|||||||
.catch(console.error)
|
.catch(console.error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create soundtrack
|
||||||
|
export function createSoundTrack(arn: AnimeNotifier, button: HTMLButtonElement) {
|
||||||
|
let soundcloud = arn.app.find("soundcloud-link") as HTMLInputElement
|
||||||
|
let anime = arn.app.find("anime-link") as HTMLInputElement
|
||||||
|
let osu = arn.app.find("osu-link") as HTMLInputElement
|
||||||
|
|
||||||
|
let soundtrack = {
|
||||||
|
soundcloud: soundcloud.value,
|
||||||
|
tags: [anime.value, osu.value],
|
||||||
|
}
|
||||||
|
|
||||||
|
button.innerText = "Adding..."
|
||||||
|
button.disabled = true
|
||||||
|
|
||||||
|
arn.post("/api/soundtrack/new", soundtrack)
|
||||||
|
.then(() => arn.app.load("/music"))
|
||||||
|
.catch(err => {
|
||||||
|
console.error(err)
|
||||||
|
arn.reloadContent()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Search
|
// Search
|
||||||
export function search(arn: AnimeNotifier, search: HTMLInputElement, e: KeyboardEvent) {
|
export function search(arn: AnimeNotifier, search: HTMLInputElement, e: KeyboardEvent) {
|
||||||
if(e.ctrlKey || e.altKey) {
|
if(e.ctrlKey || e.altKey) {
|
||||||
|
Loading…
Reference in New Issue
Block a user