diff --git a/README.md b/README.md index 9e30da0..ba6e4b3 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,14 @@ +SkunkyArt + [![Matrix room](https://img.shields.io/badge/matrix-000000?style=for-the-badge&logo=Matrix&logoColor=white)](https://go.kde.org/matrix/#/#skunkyart:ebloid.ru) # Instances -|Инстанс|Yggdrasil|I2P|Tor|NSFW|Proxifying|Country| -|:-----:|:-------:|:-:|:-:|:--:|:--------:|:-----:| +|Instance|Yggdrasil|I2P|Tor|NSFW|Proxifying|Country| +|:------:|:-------:|:-:|:-:|:--:|:--------:|:-----:| |[skunky.ebloid.ru](https://skunky.ebloid.ru/art)|[Yes](http://[201:eba5:d1fc:bf7b:cfcb:a811:4b8b:7ea3]/art)|No|No| No | No | Russia | |[clovius.club](https://skunky.clovius.club)|No|No|No| Yes | Yes | Sweden | |[bloat.cat](https://skunky.bloat.cat)|No|No|No| Yes | Yes | Romania | |[frontendfriendly.xyz](https://skunkyart.frontendfriendly.xyz)|No|No|No| Yes | Yes | Finland | +|[lumaeris.com](https://skunkyart.lumaeris.com)|No|No|No| Yes | Yes | US | # EN 🇺🇸 ## Description @@ -13,12 +16,12 @@ SkunkyArt 🦨 -- alternative frontend to DeviantArt, which will work without pr ## Config The sample config is in the `config.example.json` file. To specify your own path to the config, use the CLI argument `-c` or `--config`. * `listen` -- the address and port on which SkunkyArt will listen -* `base-path` -- the path to the instance. Example: "`base-path`:"/art/" -> https://skunky.ebloid.ru/art/ +* `base-path` -- the path to the instance. Example: `"base-path":"/art/"` -> https://skunky.ebloid.ru/art/ * `cache` -- caching system; default is off. -* * `path` -- the path to the cache -* * `lifetime` -- cache file lifetime; measured in Unix milliseconds. -* * `max-size` -- maximum file size in bytes. -* `dirs-to-memory` -- this setting determines which directories will be copied to RAM when SkunkyArt is started. Required + * `path` -- the path to the cache + * `lifetime` -- the lifetime of the file in the cache. Units: i, h, d, w, m, y. I -- minute, all other units I think are self-explanatory. + * `max-size` -- maximum file size in megabytes. +* `dirs-to-memory` -- this setting determines which directories will be copied to RAM when SkunkyArt is started. Mandatory * `download-proxy` -- proxy address for downloading files. ## Examples of reverse proxies Nginx: @@ -27,17 +30,18 @@ server { listen 443 ssl; server_name skunky.example.com; - location ((BASE URL)) { # if you have a separate subdomain for the frontend, insert '/' instead of '((BASE URL))'. - proxy_set_header Scheme $scheme; + location ((BASE URL)) { # if you have a separate subdomain for the frontend, insert '/' instead of '((BASE URL)))'. + proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $host; proxy_http_version 1.1; proxy_pass http://((IP)):((PORT)); } } ``` +Pretty much business as usual, except for the [`X-Forwarded-Proto`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto) header setting. ## How do I add my instance to the list? -To do this, you must either make a PR by adding your instance to the `instances.json` file, or report it to the room in Matrix. I don't think it needs any description. However, be aware, this list has a couple rules: -1. the instance must not use Cloudflare. +To do this, you must either make a PR by adding your instance to the `instances.json` and `README.md` files, or create an Issue, or report it to the room in Matrix. I don't think it needs any description. However, be warned, this list has a couple rules: +1. the Instance must not use Cloudflare. 2. If your instance has modified source code, you need to publish it to any free platform. For example, Github and Gitlab are not. ## Acknowledgements * [Лис⚛](https://go.kde.org/matrix/#/@fox:matrix.org) -- helped me understand Go and gave me a lot of useful advice on this language. @@ -48,11 +52,11 @@ SkunkyArt 🦨 -- альтернативный фронтенд к DeviantArt, ## Конфиг Пример конфига находится в файле `config.example.json`. Чтобы указать свой путь до конфига, используйте CLI-аргумент `-c` или `--config`. * `listen` -- адрес и порт, на котором будет слушать SkunkyArt -* `base-path` -- путь к инстансу. Пример: "base-path": "/art/" -> https://skunky.ebloid.ru/art/ +* `base-path` -- путь к инстансу. Пример: `"base-path": "/art/"` -> https://skunky.ebloid.ru/art/ * `cache` -- система кеширования; по умолчанию - выкл. -* * `path` -- путь до кеша -* * `lifetime` -- время жизни файла в кеше; измеряется в Unix-миллисекундах -* * `max-size` -- максимальный размер файла в байтах + * `path` -- путь до кеша + * `lifetime` -- время жизни файла в кеше. Единицы измерения: i, h, d, w, m, y. I -- минута, всё остальные единицы измерения, я считаю понятными и без объяснения. + * `max-size` -- максимальный размер файла в мегабайтах * `dirs-to-memory` -- данная настройка определяет какие каталоги будут скопированы в ОЗУ при запуске SkunkyArt. Обязательна * `download-proxy` -- адрес прокси для загрузки файлов ## Примеры reverse-прокси @@ -63,15 +67,16 @@ server { server_name skunky.example.com; location ((BASE URL)) { # если у вас отдельный поддомен для фронтенда, вместо '((BASE URL))' вставляйте '/' - proxy_set_header Scheme $scheme; + proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $host; proxy_http_version 1.1; proxy_pass http://((IP)):((PORT)); } } ``` +В целом, всё как обычно, за исключением настройки заголовка [`X-Forwarded-Proto`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto). ## Как добавить свой инстанс в список? -Чтобы это сделать, вы должны либо сделать PR, добавив в файл `instances.json` свой инстанс, либо сообщить о нём в комнате в Matrix. Думаю, он не нуждается в описании. Однако учтите, у этого списка есть пара правил: +Чтобы это сделать, вы должны либо сделать PR, добавив в файлы `instances.json` и `README.md` свой инстанс, либо создать Issue, или сообщить о нём в комнате в Matrix. Думаю, он не нуждается в описании. Однако учтите, у этого списка есть пара правил: 1. Инстанс не должен использовать Cloudflare. 2. Если ваш инстанс имеет модифицированный исходный код, то вам нужно опубликовать его на любую свободную площадку. Например, Github и Gitlab таковыми не являются. ## Благодарности diff --git a/TODO.md b/TODO.md index 2334695..cdb4c95 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,16 @@ # v1.3.x -* Доделать парсинг описания -* Реализовать миниатюры и оптимизировать CSS под маленькие экраны +* Написать Makefile +* Почистить говнокод +* **Доделать парсинг описания** +* Избавиться от хардкода под Linux +* ~~Реализовать стрипы в ежедневных артах~~ +* ~~Исправить баг с навигацией по страницам~~ +* ~~Сделать единицы в конфиге более понятными~~ +* Добавить возможность включить темплейты в бинарник +* ~~Реализовать миниатюры и оптимизировать CSS под маленькие экраны~~ +* **Реализовать отображение контента, отличного от картинок (видео, аудио, etc)** +* Улучшить систему кеширования: добавить рейтинг для удаления и копирование изображений в ОЗУ # v1.4 +* Реализовать API * Реализовать темы -* Реализовать многоязычный интерфейс -* Реализовать API \ No newline at end of file +* Реализовать многоязычный интерфейс \ No newline at end of file diff --git a/app/config.go b/app/config.go index c848b9c..3fb8103 100644 --- a/app/config.go +++ b/app/config.go @@ -3,14 +3,18 @@ package app import ( "encoding/json" "os" + "regexp" + "strconv" "time" + + "git.macaw.me/skunky/devianter" ) type cache_config struct { Enabled bool Path string MaxSize int64 `json:"max-size"` - Lifetime int64 + Lifetime string UpdateInterval int64 `json:"update-interval"` } @@ -20,6 +24,7 @@ type config struct { BasePath string `json:"base-path"` Cache cache_config Proxy, Nsfw bool + UserAgent string `json:"user-agent"` DownloadProxy string `json:"download-proxy"` Dirs []string `json:"dirs-to-memory"` } @@ -33,31 +38,36 @@ var CFG = config{ Path: "cache", UpdateInterval: 1, }, - Dirs: []string{"html", "css"}, - Proxy: true, - Nsfw: true, + Dirs: []string{"html", "css"}, + UserAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36", + Proxy: true, + Nsfw: true, } +var lifetimeParsed int64 + func ExecuteConfig() { go func() { - defer func() { - if r := recover(); r != nil { - recover() - } - }() for { - Templates["instances.json"] = string(Download("https://git.macaw.me/skunky/SkunkyArt/raw/branch/master/instances.json").Body) - time.Sleep(1 * time.Second) + func() { + defer func() { + if r := recover(); r != nil { + recover() + } + }() + Templates["instances.json"] = string(Download("https://git.macaw.me/skunky/SkunkyArt/raw/branch/master/instances.json").Body) + }() + time.Sleep(1 * time.Hour) } }() - const helpmsg = `SkunkyArt v1.3 [refactoring] + const helpmsg = `SkunkyArt v1.3.1 [CSS improvements for mobile and strips on Daily Deviations] Usage: - [-c|--config] - path to config - [-h|--help] - returns this message Example: ./skunkyart -c config.json -Copyright lost+skunk, X11. https://git.macaw.me/skunky/skunkyart/src/tag/v1.3` +Copyright lost+skunk, X11. https://git.macaw.me/skunky/skunkyart/src/tag/v1.3.1` a := os.Args for n, x := range a { @@ -75,15 +85,42 @@ Copyright lost+skunk, X11. https://git.macaw.me/skunky/skunkyart/src/tag/v1.3` if CFG.cfg != "" { f, err := os.ReadFile(CFG.cfg) - try_with_exitstatus(err, 1) + tryWithExitStatus(err, 1) - try_with_exitstatus(json.Unmarshal(f, &CFG), 1) + tryWithExitStatus(json.Unmarshal(f, &CFG), 1) if CFG.Cache.Enabled && !CFG.Proxy { exit("Incompatible settings detected: cannot use caching media content without proxy", 1) } - if CFG.Cache.MaxSize != 0 || CFG.Cache.Lifetime != 0 { + if CFG.Cache.Enabled { + if CFG.Cache.Lifetime != "" { + var duration int64 + day := 24 * time.Hour.Milliseconds() + numstr := regexp.MustCompile("[0-9]+").FindAllString(CFG.Cache.Lifetime, -1) + num, _ := strconv.Atoi(numstr[len(numstr)-1]) + + switch unit := CFG.Cache.Lifetime[len(CFG.Cache.Lifetime)-1:]; unit { + case "i": + duration = time.Minute.Milliseconds() + case "h": + duration = time.Hour.Milliseconds() + case "d": + duration = day + case "w": + duration = day * 7 + case "m": + duration = day * 30 + case "y": + duration = day * 360 + default: + exit("Invalid unit specified: "+unit, 1) + } + + lifetimeParsed = duration * int64(num) + } + CFG.Cache.MaxSize /= 1024 ^ 2 go InitCacheSystem() } + devianter.UserAgent = CFG.UserAgent } } diff --git a/app/parsers.go b/app/parsers.go index 0665476..b39e172 100644 --- a/app/parsers.go +++ b/app/parsers.go @@ -70,17 +70,81 @@ func (s skunkyart) ParseComments(c devianter.Comments) string { return cmmts.String() } -func (s skunkyart) DeviationList(devs []devianter.Deviation, content ...DeviationList) string { - var list strings.Builder +func (s skunkyart) DeviationList(devs []devianter.Deviation, allowAtom bool, content ...DeviationList) string { if s.Atom && s.Page > 1 { s.ReturnHTTPError(400) return "" - } else if s.Atom { + } + + var list, listContent strings.Builder + + for i, l := 0, len(devs); i < l; i++ { + data := &devs[i] + if preview, fullview := ParseMedia(data.Media, 320), ParseMedia(data.Media); !(data.NSFW && !CFG.Nsfw) { + if allowAtom && s.Atom { + id := strconv.Itoa(data.ID) + listContent.WriteString(``) + listContent.WriteString(data.Author.Username) + listContent.WriteString(``) + listContent.WriteString(data.Title) + listContent.WriteString(``) + listContent.WriteString(id) + listContent.WriteString(``) + listContent.WriteString(data.PublishedTime.UTC().Format("Mon, 02 Jan 2006 15:04:05 -0700")) + listContent.WriteString(``) + listContent.WriteString(``) + listContent.WriteString(data.Title) + listContent.WriteString(`

`) + listContent.WriteString(ParseDescription(data.TextContent)) + listContent.WriteString(`

`) + } else { + listContent.WriteString(`
`) + if fullview != "" && preview != "" { + listContent.WriteString(``) + } else { + listContent.WriteString(`

[ TEXT ]

`) + } + listContent.WriteString(`
`) + listContent.WriteString(data.Author.Username) + listContent.WriteString(" - ") + listContent.WriteString(data.Title) + + if data.NSFW { + listContent.WriteString(` [NSFW]`) + } + if data.AI { + listContent.WriteString(" [🤖]") + } + if data.DD { + listContent.WriteString(` [DD]`) + } + + listContent.WriteString("
") + } + } + } + + if allowAtom && s.Atom { list.WriteString(``) + list.WriteString(``) if s.Type == 0 { list.WriteString("Daily Deviations") - } else if len(devs) != 0 { + } else if s.Type == 'g' && len(devs) != 0 { list.WriteString(devs[0].Author.Username) } else { list.WriteString("SkunkyArt") @@ -90,75 +154,16 @@ func (s skunkyart) DeviationList(devs []devianter.Deviation, content ...Deviatio list.WriteString(`<link rel="alternate" href="`) list.WriteString(Host) list.WriteString(`"/>`) + + list.WriteString(listContent.String()) + + list.WriteString("</feed>") + wr(s.Writer, list.String()) } else { list.WriteString(`<div class="content">`) - } - for _, data := range devs { - if !(data.NSFW && !CFG.Nsfw) { - url := ParseMedia(data.Media) - if s.Atom { - id := strconv.Itoa(data.ID) - list.WriteString(`<entry><author><name>`) - list.WriteString(data.Author.Username) - list.WriteString(`</name></author><title>`) - list.WriteString(data.Title) - list.WriteString(``) - list.WriteString(id) - list.WriteString(``) - list.WriteString(data.PublishedTime.UTC().Format("Mon, 02 Jan 2006 15:04:05 -0700")) - list.WriteString(``) - list.WriteString(``) - list.WriteString(data.Title) - list.WriteString(`

`) - list.WriteString(ParseDescription(data.TextContent)) - list.WriteString(`

`) - } else { - list.WriteString(`
`) - if url != "" { - list.WriteString(``) - } else { - list.WriteString(`

[ TEXT ]

`) - } - list.WriteString(`
`) - list.WriteString(data.Author.Username) - list.WriteString(" - ") - list.WriteString(data.Title) - // шильдики нсфв, аи и ежедневного поста - if data.NSFW { - list.WriteString(` [NSFW]`) - } - if data.AI { - list.WriteString(" [🤖]") - } - if data.DD { - list.WriteString(` [DD]`) - } + list.WriteString(listContent.String()) - list.WriteString("
") - } - } - } - - if s.Atom { - list.WriteString("
") - s.Writer.Write([]byte(list.String())) - return "" - } else { list.WriteString("") if content != nil { list.WriteString(s.NavBase(content[0])) @@ -177,7 +182,7 @@ type text struct { } func ParseDescription(dscr devianter.Text) string { - var parseddescription strings.Builder + var parsedDescription strings.Builder TagBuilder := func(content string, tags ...string) string { l := len(tags) for x := 0; x < l; x++ { @@ -274,16 +279,18 @@ func ParseDescription(dscr devianter.Text) string { switch x.Type { case "atomic": - d := entities[x.EntityRanges[0].Key] - parseddescription.WriteString(``) + if len(x.EntityRanges) != 0 { + d := entities[x.EntityRanges[0].Key] + parsedDescription.WriteString(``) + } case "unstyled": if l := len(Styles); l != 0 { for n, r := range Styles { @@ -292,31 +299,31 @@ func ParseDescription(dscr devianter.Text) string { tag = "h2" } - parseddescription.WriteString(x.Text[:r.From]) + parsedDescription.WriteString(x.Text[:r.From]) if len(urls) != 0 && len(x.EntityRanges) != 0 { ra := &x.EntityRanges[0] - parseddescription.WriteString(``) - parseddescription.WriteString(r.TXT) - parseddescription.WriteString(``) + parsedDescription.WriteString(``) + parsedDescription.WriteString(r.TXT) + parsedDescription.WriteString(``) } else if l > n+1 { - parseddescription.WriteString(r.TXT) + parsedDescription.WriteString(r.TXT) } - parseddescription.WriteString(TagBuilder(tag, x.Text[r.To:])) + parsedDescription.WriteString(TagBuilder(tag, x.Text[r.To:])) } } else { - parseddescription.WriteString(x.Text) + parsedDescription.WriteString(x.Text) } } - parseddescription.WriteString("
") + parsedDescription.WriteString("
") } } else if dl != 0 { for tt := html.NewTokenizer(strings.NewReader(dscr.Html.Markup)); ; { switch tt.Next() { case html.ErrorToken: - return parseddescription.String() + return parsedDescription.String() case html.StartTagToken, html.EndTagToken, html.SelfClosingTagToken: token := tt.Token() switch token.Data { @@ -324,11 +331,11 @@ func ParseDescription(dscr devianter.Text) string { for _, a := range token.Attr { if a.Key == "href" { url := DeleteTrackingFromUrl(a.Val) - parseddescription.WriteString(``) - parseddescription.WriteString(GetValueOfTag(tt)) - parseddescription.WriteString(" ") + parsedDescription.WriteString(``) + parsedDescription.WriteString(GetValueOfTag(tt)) + parsedDescription.WriteString(" ") } } case "img": @@ -344,24 +351,24 @@ func ParseDescription(dscr devianter.Text) string { } if title != "" { for x := -1; x < b; x++ { - parseddescription.WriteString(``) + parsedDescription.WriteString(``) } } } case "br", "li", "ul", "p", "b": - parseddescription.WriteString(token.String()) + parsedDescription.WriteString(token.String()) case "div": - parseddescription.WriteString("

") + parsedDescription.WriteString("

") } case html.TextToken: - parseddescription.Write(tt.Text()) + parsedDescription.Write(tt.Text()) } } } - return parseddescription.String() + return parsedDescription.String() } diff --git a/app/router.go b/app/router.go index 0dd2f79..33c3189 100644 --- a/app/router.go +++ b/app/router.go @@ -1,7 +1,6 @@ package app import ( - "io" "net/http" u "net/url" "strconv" @@ -44,7 +43,7 @@ func Router() { // функция, что управляет всем handle := func(w http.ResponseWriter, r *http.Request) { - if h := r.Header["Scheme"]; len(h) != 0 && h[0] == "https" { + if h := r.Header["X-Forwarded-Proto"]; len(h) != 0 && h[0] == "https" { Host = h[0] + "://" + r.Host } else { Host = "http://" + r.Host @@ -97,10 +96,14 @@ func Router() { skunky.About() case "stylesheet": w.Header().Add("content-type", "text/css") - io.WriteString(w, Templates["skunky.css"]) + wr(w, Templates["skunky.css"]) + case "favicon.ico": + wr(w, Templates["logo.png"]) } } http.HandleFunc("/", handle) - try_with_exitstatus(http.ListenAndServe(CFG.Listen, nil), 1) + println("SkunkyArt is listening on", CFG.Listen) + + tryWithExitStatus(http.ListenAndServe(CFG.Listen, nil), 1) } diff --git a/app/util.go b/app/util.go index 3f69e47..11f81a1 100644 --- a/app/util.go +++ b/app/util.go @@ -26,7 +26,7 @@ func try(e error) { println(e.Error()) } } -func try_with_exitstatus(err error, code int) { +func tryWithExitStatus(err error, code int) { if err != nil { exit(err.Error(), code) } @@ -87,7 +87,7 @@ func Download(url string) (d Downloaded) { req, e := http.NewRequest("GET", url, nil) try(e) - req.Header.Set("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0.0") + req.Header.Set("User-Agent", CFG.UserAgent) resp, e := cli.Do(req) try(e) @@ -148,14 +148,14 @@ func InitCacheSystem() { try(e) for _, a := range dirnames { a = c.Path + "/" + a - if c.Lifetime != 0 { + if c.Lifetime != "" { now := time.Now().UnixMilli() f, _ := os.Stat(a) stat := f.Sys().(*syscall.Stat_t) time := time.Unix(stat.Ctim.Unix()).UnixMilli() - if time+c.Lifetime <= now { + if time+lifetimeParsed <= now { try(os.RemoveAll(a)) } } @@ -172,19 +172,19 @@ func InitCacheSystem() { func CopyTemplatesToMemory() { for _, dirname := range CFG.Dirs { dir, e := os.ReadDir(dirname) - try_with_exitstatus(e, 1) + tryWithExitStatus(e, 1) for _, x := range dir { file, e := os.ReadFile(dirname + "/" + x.Name()) - try_with_exitstatus(e, 1) + tryWithExitStatus(e, 1) Templates[x.Name()] = string(file) } } } /* PARSING HELPERS */ -func ParseMedia(media devianter.Media) string { - url := devianter.UrlFromMedia(media) +func ParseMedia(media devianter.Media, thumb ...int) string { + url := devianter.UrlFromMedia(media, thumb...) if len(url) != 0 && CFG.Proxy { url = url[21:] dot := strings.Index(url, ".") @@ -197,9 +197,10 @@ func ParseMedia(media devianter.Media) string { func ConvertDeviantArtUrlToSkunkyArt(url string) (output string) { if len(url) > 32 && url[27:32] != "stash" { url = url[27:] - toart := strings.Index(url, "/art/") - if toart != -1 { - output = UrlBuilder("post", url[:toart], url[toart+5:]) + firstshash := strings.Index(url, "/") + lastshash := firstshash + strings.Index(url[firstshash+1:], "/") + if lastshash != -1 { + output = UrlBuilder("post", url[:firstshash], url[lastshash+2:]) } } return @@ -236,13 +237,9 @@ type DeviationList struct { // FIXME: на некоротрых артах первая страница может вызывать полное отсутствие панели навигации. func (s skunkyart) NavBase(c DeviationList) string { - // TODO: сделать понятнее - // навигация по страницам var list strings.Builder - list.WriteString("
") - p := s.Page - // функция для генерации ссылок + list.WriteString("
") prevrev := func(msg string, page int, onpage bool) { if !onpage { list.WriteString(` 0 { - // назад - for x := p - 6; x < p && x > 0; x++ { - prevrev(strconv.Itoa(x), x, false) - } - - // вперёд - for x := p; x <= p+6 && c.Pages > p+6; x++ { - if x == p { - prevrev("", x, true) - x++ + for i, x := p-6, 0; (i <= c.Pages && i <= p+6) && x < 12; i++ { + if i > 0 { + var onPage bool + if i == p { + onPage = true } - if x > p { - prevrev(strconv.Itoa(x), x, false) - } + prevrev(strconv.Itoa(i), i, onPage) + x++ } } - // вперёд-назад if c.More { prevrev("| Next =>", p+1, false) } diff --git a/app/wrapper.go b/app/wrapper.go index ca39af7..51d76a9 100644 --- a/app/wrapper.go +++ b/app/wrapper.go @@ -48,6 +48,7 @@ type skunkyart struct { } SomeList string + DDStrips string Deviation struct { Post devianter.Post Related string @@ -93,7 +94,10 @@ func (s skunkyart) GRUser() { var g devianter.Group g.Name = s.Query - s.Templates.GroupUser.GR = g.GroupFunc() + var err error + s.Templates.GroupUser.GR, err = g.GetGroup() + try(err) + group := &s.Templates.GroupUser switch s.Type { @@ -135,7 +139,7 @@ func (s skunkyart) GRUser() { group.About.Interests += interest.String() } } - group.About.Comments = s.ParseComments(devianter.CommentsFunc( + group.About.Comments = s.ParseComments(devianter.GetComments( strconv.Itoa(group.GR.Gruser.ID), "", s.Page, @@ -161,9 +165,11 @@ func (s skunkyart) GRUser() { s.Page++ } - gallery := g.Gallery(s.Page, folderid) + gallery, err := g.GetGallery(s.Page, folderid) + try(err) + if folderid > 0 { - group.Gallery.List = s.DeviationList(gallery.Content.Results, DeviationList{ + group.Gallery.List = s.DeviationList(gallery.Content.Results, true, DeviationList{ More: gallery.Content.HasMore, }) } else { @@ -204,7 +210,7 @@ func (s skunkyart) GRUser() { } if x.Name == "folder_deviations" { - group.Gallery.List = s.DeviationList(x.ModuleData.Folder.Deviations, DeviationList{ + group.Gallery.List = s.DeviationList(x.ModuleData.Folder.Deviations, true, DeviationList{ Pages: x.ModuleData.Folder.Pages, More: x.ModuleData.Folder.HasMore, }) @@ -227,7 +233,7 @@ func (s skunkyart) Deviation(author, postname string) { post := &s.Templates.Deviation id := id_search[len(id_search)-1] - post.Post = devianter.DeviationFunc(id, author) + post.Post = devianter.GetDeviation(id, author) if post.Post.Deviation.TextContent.Excerpt != "" { post.Post.Description = ParseDescription(post.Post.Deviation.TextContent) @@ -239,7 +245,7 @@ func (s skunkyart) Deviation(author, postname string) { post.Post.IMG = ParseMedia(post.Post.Deviation.Media) for _, x := range post.Post.Deviation.Extended.RelatedContent { if len(x.Deviations) != 0 { - post.Related += s.DeviationList(x.Deviations) + post.Related += s.DeviationList(x.Deviations, false) } } @@ -259,7 +265,7 @@ func (s skunkyart) Deviation(author, postname string) { post.Post.Comments.Cursor = "" } - post.Comments = s.ParseComments(devianter.CommentsFunc(id, post.Post.Comments.Cursor, s.Page, 1)) + post.Comments = s.ParseComments(devianter.GetComments(id, post.Post.Comments.Cursor, s.Page, 1)) s.ExecuteTemplate("deviantion.htm", &s) } else { @@ -268,25 +274,38 @@ func (s skunkyart) Deviation(author, postname string) { } func (s skunkyart) DD() { - dd := devianter.DailyDeviationsFunc(s.Page) - s.Templates.SomeList = s.DeviationList(dd.Deviations, DeviationList{ + dd := devianter.GetDailyDeviations(s.Page) + var strips strings.Builder + for _, x := range dd.Strips { + strips.WriteString(`

# `) + strips.WriteString(x.Title) + strips.WriteString(`

`) + + strips.WriteString(s.DeviationList(x.Deviations, false)) + } + s.Templates.DDStrips = strips.String() + s.Templates.SomeList = s.DeviationList(dd.Deviations, true, DeviationList{ Pages: 0, More: dd.HasMore, }) if !s.Atom { - s.ExecuteTemplate("list.htm", &s) + s.ExecuteTemplate("daily.htm", &s) } } func (s skunkyart) Search() { s.Atom = false - var e error + var err error ss := &s.Templates.Search switch s.Type { case 'a', 't': - ss.Content, e = devianter.SearchFunc(s.Query, s.Page, s.Type) + ss.Content, err = devianter.PerformSearch(s.Query, s.Page, s.Type) case 'g': - ss.Content, e = devianter.SearchFunc(s.Query, s.Page, s.Type, s.Args.Get("usr")) + ss.Content, err = devianter.PerformSearch(s.Query, s.Page, s.Type, s.Args.Get("usr")) case 'r': // скраппер, поскольку девиантартовцы зажопили гостевое API для поиска групп var ( usernames = make(map[int]string) @@ -333,10 +352,10 @@ func (s skunkyart) Search() { default: s.ReturnHTTPError(400) } - try(e) + try(err) if s.Type != 'r' { - ss.List = s.DeviationList(ss.Content.Results, DeviationList{ + ss.List = s.DeviationList(ss.Content.Results, false, DeviationList{ Pages: ss.Content.Pages, More: ss.Content.HasMore, }) diff --git a/config.example.json b/config.example.json index 1a78535..b4d1ce2 100644 --- a/config.example.json +++ b/config.example.json @@ -4,15 +4,17 @@ "cache": { "enabled": true, "path": "/home/skunk/projects/skunkyart/cache", - "lifetime": null, - "max-size": 100000, + "lifetime": "1w", + "max-size": 1024, "update-interval": 5 }, "dirs-to-memory": [ "/home/skunk/projects/skunkyart/html", - "/home/skunk/projects/skunkyart/css" + "/home/skunk/projects/skunkyart/css", + "/home/skunk/projects/skunkyart/misc" ], - "download-proxy": null, + "download-proxy": "http://127.0.0.1:8080", + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36", "proxy": true, "nsfw": false } diff --git a/css/skunky.css b/css/skunky.css index 9d041f0..2126968 100644 --- a/css/skunky.css +++ b/css/skunky.css @@ -131,28 +131,64 @@ form input, button, select { } /* SCREEN OPTIMISATIONS */ -@media screen and (orientation: portrait) { - header { - scale: 155%; - justify-content: center; +@media (orientation: portrait) { + * { + font-size: 120% } + + ul { + font-size: 80% + } + + center form { + font-size: 60% + } + + header form { + font-size: 60%; + } + header, center { + text-align: center; + display: block; + clear: both; + font-size: 200%; + } + .content { margin: auto; display: inherit; scale: 100%; } .block { - max-width: 60%; + margin-top: 10%; + max-width: 200%; + } + .folder-item { + width: 25% + } + .folders { + display: flexbox; + justify-content: center + } + figure img { + width: 10% + } + figure a img { + width: 100% + } + .msg { + font-size: 60%; + max-width: 80% } } -@media screen and (max-width: 1462px) { +@media (max-width: 1462px) and (orientation: landscape) { .block { max-width: 30%; } } -@media screen and (min-width: 788px) and (max-width: 884px) { +@media (min-width: 788px) and (max-width: 884px) { .block { max-width: 35%; } diff --git a/go.mod b/go.mod index 4000554..7e5e771 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,8 @@ module skunkyart go 1.22.3 +replace git.macaw.me/skunky/devianter v0.2.0 => /home/skunk/projects/devianter + require ( git.macaw.me/skunky/devianter v0.2.0 golang.org/x/net v0.27.0 diff --git a/html/about.htm b/html/about.htm index 54e5418..31f58c8 100644 --- a/html/about.htm +++ b/html/about.htm @@ -58,6 +58,6 @@ {{end}} -

Copyright lost+skunk, X11. SkunkyArt v1.3

+

Copyright lost+skunk, X11. SkunkyArt v1.3.1

\ No newline at end of file diff --git a/html/list.htm b/html/daily.htm similarity index 75% rename from html/list.htm rename to html/daily.htm index b2472c4..22e9275 100644 --- a/html/list.htm +++ b/html/daily.htm @@ -1,7 +1,7 @@ - SkunkyArt + SkunkyArt | Daily Deviations
@@ -17,6 +17,11 @@ + {{if ne .Templates.DDStrips ""}} +

# Strips

+ {{.Templates.DDStrips}} + {{end}} +

# Content

{{.Templates.SomeList}}
\ No newline at end of file diff --git a/instances.json b/instances.json index ebb75c2..eeb329a 100644 --- a/instances.json +++ b/instances.json @@ -44,6 +44,17 @@ "nsfw": true, "proxy": true } + }, + { + "title": "lumaeris.com", + "country": "US", + "urls": [{ + "clearnet": "https://skunkyart.lumaeris.com" + }], + "settings": { + "nsfw": true, + "proxy": true + } } ] } \ No newline at end of file diff --git a/misc/logo.png b/misc/logo.png new file mode 100644 index 0000000..e895de7 Binary files /dev/null and b/misc/logo.png differ diff --git a/services/skunkyart.example.openrc b/services/skunkyart.example.openrc new file mode 100755 index 0000000..d89d5b2 --- /dev/null +++ b/services/skunkyart.example.openrc @@ -0,0 +1,13 @@ +#!/sbin/openrc-run + +directory= +# command_args="-c $directory/config.json" # if SA wasn't start, try to uncomment this line +command=$directory/skunkyart + +name="SkunkyArt" +description="Privacy frontend for deviantart.com" +supervisor=supervise-daemon + +depend() { + need net +} \ No newline at end of file diff --git a/services/skunkyart.example.service b/services/skunkyart.example.service new file mode 100644 index 0000000..6531cab --- /dev/null +++ b/services/skunkyart.example.service @@ -0,0 +1,11 @@ +# Note: i didn't use systemd, so it can be not works :) + +[Unit] +Description=Privacy frontend for deviantart.com + +[Service] +Directory= +ExecStart= + +[Install] +WantedBy=multi-user.target diff --git a/skunkyart.example.openrc b/skunkyart.example.openrc deleted file mode 100755 index aba74ce..0000000 --- a/skunkyart.example.openrc +++ /dev/null @@ -1,11 +0,0 @@ -#!/sbin/openrc-run -name="SkunkyArt" -description="Privacy frontend for deviantart.com" -supervisor=supervise-daemon -command= -command_args="-c " -directory="" - -depend() { - need net -} \ No newline at end of file