From 9d1890d8f789bf3d6a90fc98bb04b2bf7e84cea8 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sun, 8 Apr 2018 12:59:36 +0200 Subject: [PATCH] Cleanup --- pages/anime/episodes.pixy | 4 +-- pages/calendar/calendar.go | 4 +-- pages/episode/episode.pixy | 2 +- .../add-forum-creators/add-forum-creators.go | 17 ------------- .../delete-private-data.go | 2 +- patches/fix-image-ids/fix-image-ids.go | 25 ++++++++----------- patches/post-texts/post-texts.go | 2 +- scripts/AnimeNotifier.ts | 23 ++++++++++++++++- scripts/StatusMessage.ts | 5 ++++ 9 files changed, 44 insertions(+), 40 deletions(-) delete mode 100644 patches/add-forum-creators/add-forum-creators.go diff --git a/pages/anime/episodes.pixy b/pages/anime/episodes.pixy index 123bf09b..6f63353e 100644 --- a/pages/anime/episodes.pixy +++ b/pages/anime/episodes.pixy @@ -15,7 +15,7 @@ component AnimeEpisodes(anime *arn.Anime, episodes []*arn.AnimeEpisode, user *ar else span - - if validator.IsValidDate(episode.AiringDate.Start) + if validate.Date(episode.AiringDate.Start) .episode-airing-date-start.utc-airing-date(data-start-date=episode.AiringDate.Start, data-end-date=episode.AiringDate.End, data-episode-number=episode.Number)= episode.AiringDate.StartDateHuman() //- table.episodes @@ -37,7 +37,7 @@ component AnimeEpisodes(anime *arn.Anime, episodes []*arn.AnimeEpisode, user *ar //- RawIcon("eye") //- //- a(href="https://translate.google.com/#ja/en/" + episode.Title.Japanese, target="_blank", rel="noopener") //- //- RawIcon("google") - //- if validator.IsValidDate(episode.AiringDate.Start) + //- if validate.Date(episode.AiringDate.Start) //- td.episode-airing-date-start.utc-airing-date(data-start-date=episode.AiringDate.Start, data-end-date=episode.AiringDate.End, data-episode-number=episode.Number)= episode.AiringDate.StartDateHuman() //- else //- td.episode-airing-date-start \ No newline at end of file diff --git a/pages/calendar/calendar.go b/pages/calendar/calendar.go index 77767ca5..9f4b3242 100644 --- a/pages/calendar/calendar.go +++ b/pages/calendar/calendar.go @@ -6,7 +6,7 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/arn" - "github.com/animenotifier/arn/validator" + "github.com/animenotifier/arn/validate" "github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/utils" ) @@ -55,7 +55,7 @@ func Get(ctx *aero.Context) string { } for _, episode := range animeEpisodes.Items { - if !validator.IsValidDate(episode.AiringDate.Start) { + if !validate.Date(episode.AiringDate.Start) { continue } diff --git a/pages/episode/episode.pixy b/pages/episode/episode.pixy index 1b13b6ee..09c4e60c 100644 --- a/pages/episode/episode.pixy +++ b/pages/episode/episode.pixy @@ -11,7 +11,7 @@ component AnimeEpisode(anime *arn.Anime, episode *arn.AnimeEpisode, user *arn.Us .episode-view-title Japanese(episode.Title.Japanese) - if validator.IsValidDate(episode.AiringDate.Start) + if validate.Date(episode.AiringDate.Start) p.episode-view-airing-date span.utc-airing-date(data-start-date=episode.AiringDate.Start, data-end-date=episode.AiringDate.End, data-episode-number=episode.Number)= episode.AiringDate.StartDateHuman() diff --git a/patches/add-forum-creators/add-forum-creators.go b/patches/add-forum-creators/add-forum-creators.go deleted file mode 100644 index 7b4acb67..00000000 --- a/patches/add-forum-creators/add-forum-creators.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import "github.com/animenotifier/arn" - -func main() { - defer arn.Node.Close() - - for post := range arn.StreamPosts() { - post.CreatedBy = post.AuthorID - post.Save() - } - - for thread := range arn.StreamThreads() { - thread.CreatedBy = thread.AuthorID - thread.Save() - } -} diff --git a/patches/delete-private-data/delete-private-data.go b/patches/delete-private-data/delete-private-data.go index f20f9615..366478c5 100644 --- a/patches/delete-private-data/delete-private-data.go +++ b/patches/delete-private-data/delete-private-data.go @@ -31,7 +31,7 @@ func main() { user.Accounts.Facebook.ID = "" user.Accounts.Google.ID = "" user.AgeRange = arn.UserAgeRange{} - user.Location = arn.Location{} + user.Location = &arn.Location{} user.PushSubscriptions().Items = []*arn.PushSubscription{} user.PushSubscriptions().Save() diff --git a/patches/fix-image-ids/fix-image-ids.go b/patches/fix-image-ids/fix-image-ids.go index ac286cd8..c7a8265a 100644 --- a/patches/fix-image-ids/fix-image-ids.go +++ b/patches/fix-image-ids/fix-image-ids.go @@ -1,23 +1,18 @@ package main -import ( - "github.com/animenotifier/arn" - "github.com/fatih/color" -) - func main() { - color.Yellow("Moving Kitsu IDs to new IDs") + // color.Yellow("Moving Kitsu IDs to new IDs") - defer color.Green("Finished.") - defer arn.Node.Close() + // defer color.Green("Finished.") + // defer arn.Node.Close() - for anime := range arn.StreamAnime() { - kitsuID := anime.GetMapping("kitsu/anime") + // for anime := range arn.StreamAnime() { + // kitsuID := anime.GetMapping("kitsu/anime") - if kitsuID == "" { - continue - } + // if kitsuID == "" { + // continue + // } - anime.MoveImageFiles(kitsuID, anime.ID) - } + // anime.MoveImageFiles(kitsuID, anime.ID) + // } } diff --git a/patches/post-texts/post-texts.go b/patches/post-texts/post-texts.go index 4c5fb314..3631a12f 100644 --- a/patches/post-texts/post-texts.go +++ b/patches/post-texts/post-texts.go @@ -13,7 +13,7 @@ func main() { for post := range arn.StreamPosts() { // Fix text color.Yellow(post.Text) - post.Text = autocorrect.FixPostText(post.Text) + post.Text = autocorrect.PostText(post.Text) color.Green(post.Text) // Tags diff --git a/scripts/AnimeNotifier.ts b/scripts/AnimeNotifier.ts index 142cccdb..77d4778d 100644 --- a/scripts/AnimeNotifier.ts +++ b/scripts/AnimeNotifier.ts @@ -34,6 +34,7 @@ export default class AnimeNotifier { diffCompletedForCurrentPath: boolean lastReloadContentPath: string currentSoundTrackId: string + etags: Map constructor(app: Application) { this.app = app @@ -195,7 +196,27 @@ export default class AnimeNotifier { // Bind unload event window.addEventListener("beforeunload", this.onBeforeUnload.bind(this)) - // Download popular anime titles for the search + // Check etags of scripts and styles + this.etags = new Map() + + delay(2000).then(async () => { + let response = await fetch("/scripts") + let newETag = response.headers.get("ETag") + let oldETag = this.etags.get("/scripts") + + this.etags.set("/scripts", newETag) + console.log("etags", this.etags) + + if(!oldETag || !newETag) { + return + } + + if(oldETag !== newETag) { + this.statusMessage.showInfo("A new version of the website is available. Please refresh the page.", -1) + } + }) + + // // Download popular anime titles for the search // let response = await fetch("/api/popular/anime/titles/500") // let titles = await response.json() // let titleList = document.createElement("datalist") diff --git a/scripts/StatusMessage.ts b/scripts/StatusMessage.ts index 195fec4c..6aeaecca 100644 --- a/scripts/StatusMessage.ts +++ b/scripts/StatusMessage.ts @@ -17,6 +17,11 @@ export default class StatusMessage { this.container.classList.remove("fade-out") this.container.dataset.messageId = messageId + // Negative duration means we're displaying it forever until the user manually closes it + if(duration === -1) { + return + } + delay(duration || 4000).then(() => { if(this.container.dataset.messageId !== messageId) { return