diff --git a/moira_db.go b/moira_db.go index 23f7b8b..446ef78 100644 --- a/moira_db.go +++ b/moira_db.go @@ -241,7 +241,18 @@ func sessions_is_loggedIn(resp http.ResponseWriter, req *http.Request) (ret bool return false, nil } + val_str, ok := val.(string) + if !ok{ + fmt.Println("non-string user") + return false, nil + } + //if val not in user_db: false,nil + if _,ok:=db_user[val_str]; !ok{ + fmt.Println("user not in db") + return false, nil + } + fmt.Println(val) return true, nil } @@ -257,7 +268,7 @@ type Film struct{ Year int } -var db_film = make(map[string]any) +var db_film = make(map[string]any) // the any is *Film func findURL_in_msg(in_msg string) (_ string,err error){ @@ -285,7 +296,7 @@ func resolve_redirs(in_url string) (string,error){ return resp.Request.URL.String(), nil } -func fetch_filmInfo(in_url string) (_ Film, err error){ +func fetch_filmInfo(in_url string) (_ *Film, err error){ parsedUrl, err := url.Parse(in_url) if err != nil{ return } parsedUrl.RawQuery = "" @@ -342,7 +353,7 @@ func fetch_filmInfo(in_url string) (_ Film, err error){ if(len(gjson.GetBytes(resp_text, "title").String())>0){ titles[gjson.GetBytes(resp_text, "title.lang").String()] = gjson.GetBytes(resp_text, "title.title").String() } - return Film{ + return &Film{ Title_orig: (func()string{ if val,ok:=titles["_orig"]; ok{ return val @@ -386,7 +397,7 @@ func fetch_filmInfo(in_url string) (_ Film, err error){ titles["_orig"] = val } } - return Film{ + return &Film{ Title_orig: (func()string{ if val,ok:=titles["_orig"]; ok{ return val @@ -421,6 +432,21 @@ func fetch_filmInfo(in_url string) (_ Film, err error){ } } + +type List struct{ + Name, + Desc, + Img string + + FilmIDs []*Film + + CreatedTS, + UpdatedTS int64 // UNIX timestamps +} +var db_list = make(map[string]any) // the any is *List + + + func hdlr_root(template_renders map[string]struct{Template string;Context *map[string]any}) http.HandlerFunc{ fSrv := http.FileServer(http.Dir("./website/static")) @@ -472,10 +498,28 @@ func hdlr_film_parseMsg(resp http.ResponseWriter, req *http.Request){ fmt.Println(t_url) t_url_noRed, _ := resolve_redirs(t_url) fmt.Println(t_url_noRed) + + film_already_in_db := false + var film_found_id string + for i,i_film := range db_film{ + if i_film.(*Film).Source == t_url_noRed{ + film_already_in_db = true + film_found_id = i + break + } + } + + if(film_already_in_db){ + http.Redirect(resp, req, "/film/view/?id="+film_found_id, http.StatusFound) + return + } + t_film, _ := fetch_filmInfo(t_url_noRed) db_film[fmt.Sprintf("%d",len(db_film))] = t_film + db_list["0"].(*List).FilmIDs = append(db_list["0"].(*List).FilmIDs, db_film[fmt.Sprintf("%d",len(db_film)-1)].(*Film)) + t_json, _ := json.MarshalIndent(db_film, "", " ") fmt.Printf("%+v\n", string(t_json)) fmt.Println("/film/view/?id="+fmt.Sprintf("%d",len(db_film)-1)) @@ -488,6 +532,14 @@ func main(){ fmt.Println("CLIENT_SECRET:", oauth2_dc_config.ClientSecret); fmt.Println("SESSIONS_SECRET:", os.Getenv("SESSIONS_SECRET")); + db_list["0"] = &List{ + Name: "film_dump_watchlist", + FilmIDs: []*Film{}, + + CreatedTS: 0, + UpdatedTS: 0, + } + //t_film, _ := fetch_filmInfo("https://www.filmweb.pl/film/Spirited+Away%3A+W+krainie+Bog%C3%B3w-2001-33288") //t_film, _ := fetch_filmInfo("https://www.filmweb.pl/film/Pulp+Fiction-1994-1039") //t_film, _ := fetch_filmInfo("https://www.filmweb.pl/film/Kl%C4%85twa+Doliny+W%C4%99%C5%BCy-1987-6785") @@ -514,9 +566,9 @@ func main(){ template_renders := map[string]struct{Template string;Context *map[string]any} { "/": {"index.html", nil}, "/film/view/": {"film/view/index.html", &db_film}, - "/film/edit/": {"index.html", nil}, - //"/list/view/": {"index.html", nil}, - //"/list/edit/": {"index.html", nil}, + "/film/edit/": {"index.html", &db_film}, + "/list/view/": {"list/view/index.html", &db_list}, + "/list/edit/": {"index.html", &db_list}, //"/group/view/": {"index.html", nil}, //"/group/edit/": {"index.html", nil}, } diff --git a/website/static/film/view/styles.css b/website/static/film/view/styles.css index 9c1ad49..fd89326 100644 --- a/website/static/film/view/styles.css +++ b/website/static/film/view/styles.css @@ -1,3 +1,8 @@ +a{ + color: black; + text-decoration: none; +} + body{ margin: 0; diff --git a/website/static/list/view/script.js b/website/static/list/view/script.js new file mode 100644 index 0000000..e69de29 diff --git a/website/static/list/view/styles.css b/website/static/list/view/styles.css new file mode 100644 index 0000000..2e50834 --- /dev/null +++ b/website/static/list/view/styles.css @@ -0,0 +1,206 @@ +a{ + color: black; + text-decoration: none; +} + +body{ + margin: 0; + + width: 100%; +} + +*{ + font-family: "Kode Mono", monospace; + font-optical-sizing: auto; + font-weight: 400; + font-style: normal; + + /*overflow-x: hidden;*/ +} + +b{ + font-family: "Kode Mono", monospace; + font-optical-sizing: auto; + font-weight: 700; + font-style: normal; + + /*overflow-x: hidden;*/ +} + +#sectHeader, #sectFilm{ + width: 100%; +} + +#sectHeader{ + height: 10vh; + + display: flex; + flex-direction: row; + align-items: center; +} + +#sectHeader_logo{ + height: 95%; + + aspect-ratio: 1/1; + + background-image: url("/icons/moira_db_192.png"); + background-repeat: no-repeat; + background-size: contain; +} + +#sectHeader_pageInfo{ + height: 100%; + + padding-left: 5vw; + + display: flex; + flex-direction: column; + justify-content: center; +} + +#sectHeader_pageInfo_pageTypeName{ + font-size: 1.5em; +} + +#sectFilm{ + display: flex; + + flex-direction: column; +} + +#sectFilmInfo_top{ + width: 100%; + + display: flex; + flex-direction: row; +} + +#sectFilmInfo_top_left{ + width: 50%; + --sectFilmInfo_top_left_HEIGHT: min(calc(50vw * 192 / 108), 60vh); + height: var(--sectFilmInfo_top_left_HEIGHT); + + display: flex; + flex-direction: column; +} + +.sectFilmInfo_top_left_title{ + width: 100%; + height: calc(var(--sectFilmInfo_top_left_HEIGHT) / 3); + + + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + + font-size: calc(var(--sectFilmInfo_top_left_HEIGHT) / 24); +} + +.sectFilmInfo_top_left_title > div{ + width: 100%; + height: calc(var(--sectFilmInfo_top_left_HEIGHT) / 8); + + display: flex; + flex-direction: row; + align-items: center; + + position: relative; + overflow: hidden; +} + +.marquee_text0, .marquee_text1{ + width: 100%; + position: absolute; + + padding-left: 100%; +} + +.marquee_text0 > *, .marquee_text1 > *{ + width: fit-content; + position: relative; + + white-space: nowrap; + + animation: marquee_scroll 12s linear infinite; + +} + +.sectFilmInfo_top_left_title_line0 > .marquee_text1 > *{ + animation-delay: 6s; +} + +.sectFilmInfo_top_left_title_line1 > .marquee_text0 > *{ + animation-delay: 3s; +} + +.sectFilmInfo_top_left_title_line1 > .marquee_text1 > *{ + animation-delay: 9s; +} + +@keyframes marquee_scroll{ + 0%{ + transform: translateX(0); + } + + 100%{ + transform: translateX(-200%); + } +} + +#sectFilmInfo_top_right{ + width: 50%; + + display: flex; + align-items: center; + justify-content: center; +} + +#sectFilmInfo_top_right_poster{ + width: 100%; + max-height: 60vh; + + aspect-ratio: 108/192; + + background-repeat: no-repeat; + background-size: contain; + background-position: center center; +} + +#sectFilmInfo_bttm{ + width: 100%; + + display: flex; + flex-direction: row; +} + +#sectFilmInfo_bttm_left{ + width: 50%; + + display: flex; + flex-direction: column; +} + +#sectFilmInfo_bttm_right{ + width: 50%; + + display: flex; + flex-direction: column; + align-items: center; +} + +.sectDivider, .sectDivider_empty{ + width: 100%; + height: 5vh; + + margin-top: 10px; + margin-bottom: 10px; +} + +.sectDivider{ + background-image: url("/img/divider.png"); + background-size: contain; + background-repeat: repeat-x; +} + diff --git a/website/static/script.js b/website/static/script.js index 9f9334b..06a4471 100644 --- a/website/static/script.js +++ b/website/static/script.js @@ -1,12 +1,6 @@ var installPromptEvnt = null; window.onload = () => { - /*if ('serviceWorker' in navigator) { - navigator.serviceWorker.register('/empty_sw.js') - .then((reg) => console.log('SW registered:', reg.scope)) - .catch((err) => console.error('SW registration failed:', err)); - }*/ - window.addEventListener("beforeinstallprompt", (e) => { installPromptEvnt = e; document.getElementById("inp_bttn").disabled = false; @@ -16,79 +10,4 @@ window.onload = () => { installPromptEvnt.prompt(); this.disabled = true; }); - - var fetch_filmInfo = async (in_url)=>{ - // pretty good test redirect: https://share.google/mSDJehdZm6hp6vTYy - var resp; - - - //resp = await fetch("https://www.imdb.com/title/tt0245429/?ref_=nv_sr_srsg_0_tt_8_nm_0_in_0_q_spirited"); - //resp = await fetch("https://www.filmweb.pl/film/Spirited+Away%3A+W+krainie+Bog%C3%B3w-2001-33288"); - resp = await fetch(in_url); - //console.log("Redirected:", response.redirected); - console.log("Redirected URL:", resp.url); - noRed_URL = resp.url; - - - var api_URL = null; - noRed_URL = new URL(noRed_URL); - const db_host = noRed_URL.hostname; - noRed_URL.search = ''; - - switch(db_host){ - case "www.filmweb.pl": - api_URL = `https://www.filmweb.pl/api/v1/film/${noRed_URL.href.slice(noRed_URL.href.lastIndexOf("-")+1)}/preview`; - break; - - case "www.imdb.com": - // https://imdbapi.dev/ - noRed_URL.hostname = "api.imdbapi.dev"; - api_URL = noRed_URL.href.replace("/title/", "/titles/").slice(0, -1); - break; - } - console.log("API URL:", api_URL); - - - var resp = await fetch(api_URL) - var data = await resp.json(); - console.log("Ext info:", data); - - - var film_info = null; - - switch(db_host){ - case "www.filmweb.pl": - film_info = {}; - film_info["title_en"] = data["internationalTitle"] ? data["internationalTitle"]["title"] : data["originalTitle"]["title"]; - film_info["title_pl"] = data["title"]["title"]; - film_info["desc"] = data["plotOrDescriptionSynopsis"]; - film_info["year"] = data["year"]; - //film_info["img"] = data["coverPhoto"]["photo"]["sourcePath"]; - film_info["img"] = "https://fwcdn.pl/fpo"+data["poster"]["path"]; - //directors - //countries - //poster - break; - - case "www.imdb.com": - film_info = {}; - film_info["title_en"] = data["primaryTitle"]; - film_info["title_pl"] = null; - film_info["desc"] = data["plot"]; - film_info["year"] = data["startYear"]; - film_info["img"] = data["primaryImage"]["url"]; - break; - } - console.log("Film info:", film_info); - - - document.getElementById("filmInfo_title").innerHTML = film_info["title_pl"] ? film_info["title_pl"] : film_info["title_en"]; - document.getElementById("filmInfo_year").innerHTML = film_info["year"]; - document.getElementById("filmInfo_desc").innerHTML = film_info["desc"]; - document.getElementById("filmInfo_img").src = film_info["img"]; - }; - - document.getElementById("inEl").addEventListener("input", function(){ - fetch_filmInfo(this.value); - }); }; diff --git a/website/static/styles.css b/website/static/styles.css index 8f2ed5a..2e50834 100644 --- a/website/static/styles.css +++ b/website/static/styles.css @@ -1,4 +1,206 @@ -body{ - background-color: black; - color: white; +a{ + color: black; + text-decoration: none; } + +body{ + margin: 0; + + width: 100%; +} + +*{ + font-family: "Kode Mono", monospace; + font-optical-sizing: auto; + font-weight: 400; + font-style: normal; + + /*overflow-x: hidden;*/ +} + +b{ + font-family: "Kode Mono", monospace; + font-optical-sizing: auto; + font-weight: 700; + font-style: normal; + + /*overflow-x: hidden;*/ +} + +#sectHeader, #sectFilm{ + width: 100%; +} + +#sectHeader{ + height: 10vh; + + display: flex; + flex-direction: row; + align-items: center; +} + +#sectHeader_logo{ + height: 95%; + + aspect-ratio: 1/1; + + background-image: url("/icons/moira_db_192.png"); + background-repeat: no-repeat; + background-size: contain; +} + +#sectHeader_pageInfo{ + height: 100%; + + padding-left: 5vw; + + display: flex; + flex-direction: column; + justify-content: center; +} + +#sectHeader_pageInfo_pageTypeName{ + font-size: 1.5em; +} + +#sectFilm{ + display: flex; + + flex-direction: column; +} + +#sectFilmInfo_top{ + width: 100%; + + display: flex; + flex-direction: row; +} + +#sectFilmInfo_top_left{ + width: 50%; + --sectFilmInfo_top_left_HEIGHT: min(calc(50vw * 192 / 108), 60vh); + height: var(--sectFilmInfo_top_left_HEIGHT); + + display: flex; + flex-direction: column; +} + +.sectFilmInfo_top_left_title{ + width: 100%; + height: calc(var(--sectFilmInfo_top_left_HEIGHT) / 3); + + + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + + font-size: calc(var(--sectFilmInfo_top_left_HEIGHT) / 24); +} + +.sectFilmInfo_top_left_title > div{ + width: 100%; + height: calc(var(--sectFilmInfo_top_left_HEIGHT) / 8); + + display: flex; + flex-direction: row; + align-items: center; + + position: relative; + overflow: hidden; +} + +.marquee_text0, .marquee_text1{ + width: 100%; + position: absolute; + + padding-left: 100%; +} + +.marquee_text0 > *, .marquee_text1 > *{ + width: fit-content; + position: relative; + + white-space: nowrap; + + animation: marquee_scroll 12s linear infinite; + +} + +.sectFilmInfo_top_left_title_line0 > .marquee_text1 > *{ + animation-delay: 6s; +} + +.sectFilmInfo_top_left_title_line1 > .marquee_text0 > *{ + animation-delay: 3s; +} + +.sectFilmInfo_top_left_title_line1 > .marquee_text1 > *{ + animation-delay: 9s; +} + +@keyframes marquee_scroll{ + 0%{ + transform: translateX(0); + } + + 100%{ + transform: translateX(-200%); + } +} + +#sectFilmInfo_top_right{ + width: 50%; + + display: flex; + align-items: center; + justify-content: center; +} + +#sectFilmInfo_top_right_poster{ + width: 100%; + max-height: 60vh; + + aspect-ratio: 108/192; + + background-repeat: no-repeat; + background-size: contain; + background-position: center center; +} + +#sectFilmInfo_bttm{ + width: 100%; + + display: flex; + flex-direction: row; +} + +#sectFilmInfo_bttm_left{ + width: 50%; + + display: flex; + flex-direction: column; +} + +#sectFilmInfo_bttm_right{ + width: 50%; + + display: flex; + flex-direction: column; + align-items: center; +} + +.sectDivider, .sectDivider_empty{ + width: 100%; + height: 5vh; + + margin-top: 10px; + margin-bottom: 10px; +} + +.sectDivider{ + background-image: url("/img/divider.png"); + background-size: contain; + background-repeat: repeat-x; +} + diff --git a/website/templates/film/view/index.html b/website/templates/film/view/index.html index 966585b..10cbfdc 100644 --- a/website/templates/film/view/index.html +++ b/website/templates/film/view/index.html @@ -19,12 +19,16 @@
+ + +
LIST film_dump_watchlist
+
diff --git a/website/templates/index.html b/website/templates/index.html index 5fbbdd2..eec24cd 100644 --- a/website/templates/index.html +++ b/website/templates/index.html @@ -9,20 +9,46 @@ + + + + - -
- +
+ + + -
-

-


-


- +
+ +
+ +
+ +
+ +
+ LIST + film_dump_watchlist +
+
+
+ + +
+
+
+
+
+
+
+
+
+
diff --git a/website/templates/list/view/index.html b/website/templates/list/view/index.html new file mode 100644 index 0000000..8b86106 --- /dev/null +++ b/website/templates/list/view/index.html @@ -0,0 +1,100 @@ + + + + + + + + moira_db + + + + + + + + + + + + +
+ + + + +
+ LIST + {{.Name}} +
+
+ + {{range .FilmIDs}} +
+ +
+
+
+
+
+

{{.Title_orig}} | 

+

{{.Title_orig}} | 

+
+ +
+

{{.Title_orig}} | 

+

{{.Title_orig}} | 

+
+
+ +
+
+

{{.Title_PL}} | 

+

{{.Title_PL}} | 

+
+ +
+

{{.Title_PL}} | 

+

{{.Title_PL}} | 

+
+
+ +
+
+

{{.Title_EN}} | 

+

{{.Title_EN}} | 

+
+ +
+

{{.Title_EN}} | 

+

{{.Title_EN}} | 

+
+
+
+ +
+
+
+
+ +
+
+
+ +
+
+

{{.Year}}

+
+
+
+
+ {{end}} + + +
+
+
+
+ + +