Commit 048bb470ab

048bb470ab8dc3adce83d2e615f3ab369efa2199

parent: 32c61ec8ea

Unsigned

lost+skunk <skunky@macaw.me> · 2025-02-22 12:30 UTC

Переключатель кеша в озу, небольшие улучшения ксс, фикс нсфв, фикс максимального размера кеша

Layout: unified · split

app/api.go +7 −1
@@ -41,12 +41,18 @@ func (a API) Error(description string, status int) {
4141func (a API) sendMedia(d *devianter.Deviation) {
4242 mediaUrl, name := devianter.UrlFromMedia(d.Media)
4343 a.main.SetFilename(name)
44
4544 if len(mediaUrl) != 0 {
45 return
46 }
47
48 if CFG.Proxy {
4649 mediaUrl = mediaUrl[21:]
4750 dot := strings.Index(mediaUrl, ".")
4851 a.main.Writer.Header().Del("Content-Type")
4952 a.main.DownloadAndSendMedia(mediaUrl[:dot], mediaUrl[dot+11:])
53 } else {
54 a.main.Writer.Header().Add("Location", mediaUrl)
55 a.main.Writer.WriteHeader(302)
5056 }
5157}
5258
app/cache.go +45 −31
@@ -38,17 +38,7 @@ func (s skunkyart) DownloadAndSendMedia(subdomain, path string) {
3838 fileName := sha1.Sum([]byte(subdomain + path))
3939 filePath := CFG.Cache.Path + "/" + hex.EncodeToString(fileName[:])
4040
41 mx.Lock()
42 if tempFS[fileName] == nil {
43 tempFS[fileName] = &file{}
44 }
45 mx.Unlock()
46
47 if tempFS[fileName].Content != nil {
48 response = tempFS[fileName].Content
49 tempFS[fileName].Score += 2
50 break
51 } else {
41 c := func() {
5242 file, err := os.Open(filePath)
5343 if err != nil {
5444 if dwnld := Download(url.String()); dwnld.Status == 200 && dwnld.Headers["Content-Type"][0][:5] == "image" {
@@ -63,27 +53,44 @@ func (s skunkyart) DownloadAndSendMedia(subdomain, path string) {
6353 try(e)
6454 response = file
6555 }
56 }
6657
67 go func() {
68 defer restore()
69
70 mx.RLock()
71 tempFS[fileName].Content = response
72 mx.RUnlock()
73
74 for {
75 time.Sleep(1 * time.Minute)
58 if CFG.Cache.MemCache {
59 mx.Lock()
60 if tempFS[fileName] == nil {
61 tempFS[fileName] = &file{}
62 }
63 mx.Unlock()
7664
77 mx.Lock()
78 if tempFS[fileName].Score <= 0 {
79 delete(tempFS, fileName)
65 if tempFS[fileName].Content != nil {
66 response = tempFS[fileName].Content
67 tempFS[fileName].Score += 2
68 break
69 } else {
70 c()
71 go func() {
72 defer restore()
73
74 mx.RLock()
75 tempFS[fileName].Content = response
76 mx.RUnlock()
77
78 for {
79 time.Sleep(1 * time.Minute)
80
81 mx.Lock()
82 if tempFS[fileName].Score <= 0 {
83 delete(tempFS, fileName)
84 mx.Unlock()
85 return
86 }
87 tempFS[fileName].Score--
8088 mx.Unlock()
81 return
8289 }
83 tempFS[fileName].Score--
84 mx.Unlock()
85 }
86 }()
90 }()
91 }
92 } else {
93 c()
8794 }
8895 case CFG.Proxy:
8996 dwnld := Download(url.String())
@@ -112,6 +119,7 @@ func InitCacheSystem() {
112119 println(err.Error())
113120 }
114121
122 var total int64
115123 for _, file := range dir {
116124 fileName := c.Path + "/" + file.Name()
117125 fileInfo, err := file.Info()
@@ -128,9 +136,15 @@ func InitCacheSystem() {
128136 }
129137 }
130138
131 if c.MaxSize != 0 && fileInfo.Size() > c.MaxSize {
132 try(os.RemoveAll(fileName))
133 }
139 total += fileInfo.Size()
140 // if c.MaxSize != 0 && fileInfo.Size() > c.MaxSize {
141 // try(os.RemoveAll(fileName))
142 // }
143 }
144
145 if c.MaxSize != 0 && total > c.MaxSize {
146 try(os.RemoveAll(c.Path))
147 os.Mkdir(c.Path, 0700)
134148 }
135149
136150 time.Sleep(time.Second * time.Duration(c.UpdateInterval))
app/config.go +4 −3
@@ -12,12 +12,13 @@ import (
1212)
1313
1414var Release struct {
15 Version string
15 Version string
1616 Description string
1717}
1818
1919type cache_config struct {
2020 Enabled bool
21 MemCache bool `json:"memcache"`
2122 Path string
2223 MaxSize int64 `json:"max-size"`
2324 Lifetime string
@@ -93,9 +94,9 @@ func ExecuteConfig() {
9394
9495 About = instanceAbout{
9596 Proxy: CFG.Proxy,
96 Nsfw: CFG.Nsfw,
97 Nsfw: CFG.Nsfw,
9798 }
98
99
99100 static.StaticPath = CFG.StaticPath
100101 devianter.UserAgent = CFG.UserAgent
101102 }
app/wrapper.go +10 −3
@@ -36,13 +36,12 @@ func (s skunkyart) GRUser() {
3636 for _, x := range g.Gruser.Page.Modules {
3737 switch x.Name {
3838 case "about", "group_about":
39 switch g.Owner.Group {
40 case true:
39 if g.Owner.Group {
4140 var about = &x.ModuleData.GroupAbout
4241 group.Group = true
4342 group.CreationDate = x.ModuleData.GroupAbout.FoundatedAt.UTC().String()
4443 group.About.DescriptionFormatted = ParseDescription(about.Description)
45 case false:
44 } else if false {
4645 group.About.A = x.ModuleData.About
4746 var about = &group.About.A
4847 group.CreationDate = time.Unix(time.Now().Unix()-x.ModuleData.About.RegDate, 0).UTC().String()
@@ -186,6 +185,14 @@ func (s skunkyart) Deviation(author, postname string) {
186185 return
187186 }
188187
188 if post.Post.Deviation.NSFW {
189 s.Writer.WriteHeader(403)
190 wr(s.Writer, `<html><link rel="stylesheet" href="`+
191 UrlBuilder("stylesheet")+
192 `" /><h1>NSFW content are disabled on this instance.</h1></html>`)
193 return
194 }
195
189196 if post.Post.Comments.Total <= 50 {
190197 post.Post.Comments.Cursor = ""
191198 }
config.example.json +2 −1
@@ -6,11 +6,12 @@
66 "path": "cache",
77 "lifetime": null,
88 "max-size": 200,
9 "memcache": false,
910 "update-interval": 5
1011 },
1112 "static-path": "static",
1213 "download-proxy": "http://127.0.0.1:8080",
1314 "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",
1415 "proxy": true,
15 "nsfw": true
16 "nsfw": false
1617}
static/css/skunky.css +21 −9
@@ -1,6 +1,6 @@
11/* TAGS */
22html {
3 font-family: Ubuntu;
3 font-family: ubuntu, system-ui;
44 background-color:black;
55 color: rgb(234, 216, 216);
66}
@@ -45,24 +45,22 @@ input:focus {
4545 justify-content: center;
4646}
4747.block {
48 max-width: 20%;
49 height: 0%;
50 padding: 4px;
51 border-radius: 2px;
52 border: 3px solid #091f19;
48 padding: 0px 0px 6px 0px;
49 border: 3px solid #000;
5350 word-break: break-all;
5451 background-color: #091f19;
5552 margin-left: 5px;
5653 margin-top: 5px;
5754 text-align: center;
5855}
56.block h1 {
57 padding: 8.5vh;
58}
5959.block:hover {
6060 border: 3px solid #4d27d6;
6161 transition: 400ms;
6262}
63.block img, .plates .user-plate img {
64 width: 100%;
65}
63
6664.block p {
6765 word-break: break-all;
6866}
@@ -185,6 +183,20 @@ input:focus {
185183 font-size: 60%;
186184 max-width: 80%
187185 }
186 .block img, .plates .user-plate img {
187 width: 100%;
188 }
189}
190
191@media (orientation: landscape) {
192 .block {
193 width: 20%;
194 }
195 .block img, .plates .user-plate img {
196 width: 100%;
197 height: 30vh;
198 object-fit: cover;
199 }
188200}
189201
190202@media (max-width: 1462px) and (orientation: landscape) {
static/html/gruser.htm +1 −1
@@ -30,7 +30,7 @@
3030 </form> <h1>| {{.Templates.GroupUser.GR.Owner.Username}}</h1>
3131 </header>
3232 {{if eq .Type 'a'}}
33 {{if ne .Templates.GroupUser.About.BG ""}}
33 {{if and (and (ne .Templates.About.Nsfw true) (ne .Templates.GroupUser.About.BGMeta.NSFW true)) (ne .Templates.GroupUser.About.BG "")}}
3434 <a href="{{.Templates.GroupUser.About.BGMeta.Url}}" class="ubg"><img title="{{if ne .Templates.GroupUser.GR.Owner.Username .Templates.GroupUser.About.BGMeta.Author.Username}}
3535 {{.Templates.GroupUser.About.BGMeta.Author.Username}} - {{end}}{{.Templates.GroupUser.About.BGMeta.Title}}" src="{{.Templates.GroupUser.About.BG}}"></a>
3636 {{end}}