codebydante commited on
Commit
ecd0f1c
·
verified ·
1 Parent(s): e329c12

Upload 114 files

Browse files
internal/cache/disk.go CHANGED
@@ -1,47 +1,47 @@
1
- package cache
2
-
3
- import (
4
- "os"
5
- "path/filepath"
6
- "time"
7
-
8
- "go.uber.org/zap"
9
- )
10
-
11
- // StartDiskCacheEviction periodically deletes files in the cache directory that are older than maxAge.
12
- func StartDiskCacheEviction(dir string, maxAge time.Duration, log *zap.Logger) {
13
- log = log.Named("DiskCache")
14
- ticker := time.NewTicker(1 * time.Hour)
15
- defer ticker.Stop()
16
-
17
- for range ticker.C {
18
- log.Info("Running disk cache eviction cleanup")
19
- entries, err := os.ReadDir(dir)
20
- if err != nil {
21
- log.Error("Failed to read cache directory", zap.Error(err))
22
- continue
23
- }
24
-
25
- now := time.Now()
26
- var deleted int
27
- for _, entry := range entries {
28
- if entry.IsDir() {
29
- continue
30
- }
31
- info, err := entry.Info()
32
- if err != nil {
33
- continue
34
- }
35
-
36
- if now.Sub(info.ModTime()) > maxAge {
37
- err = os.Remove(filepath.Join(dir, entry.Name()))
38
- if err == nil {
39
- deleted++
40
- }
41
- }
42
- }
43
- if deleted > 0 {
44
- log.Sugar().Infof("Evicted %d files from disk cache", deleted)
45
- }
46
- }
47
- }
 
1
+ package cache
2
+
3
+ import (
4
+ "os"
5
+ "path/filepath"
6
+ "time"
7
+
8
+ "go.uber.org/zap"
9
+ )
10
+
11
+ // StartDiskCacheEviction periodically deletes files in the cache directory that are older than maxAge.
12
+ func StartDiskCacheEviction(dir string, maxAge time.Duration, log *zap.Logger) {
13
+ log = log.Named("DiskCache")
14
+ ticker := time.NewTicker(1 * time.Hour)
15
+ defer ticker.Stop()
16
+
17
+ for range ticker.C {
18
+ log.Info("Running disk cache eviction cleanup")
19
+ entries, err := os.ReadDir(dir)
20
+ if err != nil {
21
+ log.Error("Failed to read cache directory", zap.Error(err))
22
+ continue
23
+ }
24
+
25
+ now := time.Now()
26
+ var deleted int
27
+ for _, entry := range entries {
28
+ if entry.IsDir() {
29
+ continue
30
+ }
31
+ info, err := entry.Info()
32
+ if err != nil {
33
+ continue
34
+ }
35
+
36
+ if now.Sub(info.ModTime()) > maxAge {
37
+ err = os.Remove(filepath.Join(dir, entry.Name()))
38
+ if err == nil {
39
+ deleted++
40
+ }
41
+ }
42
+ }
43
+ if deleted > 0 {
44
+ log.Sugar().Infof("Evicted %d files from disk cache", deleted)
45
+ }
46
+ }
47
+ }
internal/commands/file_stream.go CHANGED
@@ -154,6 +154,17 @@ func HandleFileStreamFile(chatId int64, ctx *ext.Context, u *ext.Update, fileMed
154
  continue
155
  }
156
 
 
 
 
 
 
 
 
 
 
 
 
157
  if strings.HasPrefix(line, "Message ID (Canal):") {
158
  if currentItem != nil {
159
  idStr := strings.TrimSpace(strings.TrimPrefix(line, "Message ID (Canal):"))
@@ -229,6 +240,7 @@ func HandleFileStreamFile(chatId int64, ctx *ext.Context, u *ext.Update, fileMed
229
  // Generate Text Content Output
230
  var webpItems []ParsedFileItem
231
  var originalItems []ParsedFileItem
 
232
 
233
  // Sort by name if desired, keeping original logic if preferred. User wants alphabetical "ordenando alfabeticamente" -> Yes we can do that!
234
  for _, it := range items {
@@ -237,6 +249,8 @@ func HandleFileStreamFile(chatId int64, ctx *ext.Context, u *ext.Update, fileMed
237
  }
238
  if it.Type == "WEBP" {
239
  webpItems = append(webpItems, it)
 
 
240
  } else {
241
  originalItems = append(originalItems, it)
242
  }
@@ -248,6 +262,9 @@ func HandleFileStreamFile(chatId int64, ctx *ext.Context, u *ext.Update, fileMed
248
  sort.Slice(originalItems, func(i, j int) bool {
249
  return originalItems[i].Name < originalItems[j].Name
250
  })
 
 
 
251
 
252
  var buf bytes.Buffer
253
  buf.WriteString(fmt.Sprintf("==== %s ====\n\n", title))
@@ -275,6 +292,19 @@ func HandleFileStreamFile(chatId int64, ctx *ext.Context, u *ext.Update, fileMed
275
  for i, f := range originalItems {
276
  buf.WriteString(fmt.Sprintf("(%d) %s = %s\n", i+1, f.Name, f.LocalLink))
277
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
278
  }
279
  buf.WriteString("\n")
280
 
 
154
  continue
155
  }
156
 
157
+ if strings.HasPrefix(line, "[VIDEO]") {
158
+ if currentItem != nil && currentItem.MessageID != 0 {
159
+ items = append(items, *currentItem)
160
+ }
161
+ currentItem = &ParsedFileItem{
162
+ Type: "VIDEO",
163
+ Name: strings.TrimSpace(strings.TrimPrefix(line, "[VIDEO]")),
164
+ }
165
+ continue
166
+ }
167
+
168
  if strings.HasPrefix(line, "Message ID (Canal):") {
169
  if currentItem != nil {
170
  idStr := strings.TrimSpace(strings.TrimPrefix(line, "Message ID (Canal):"))
 
240
  // Generate Text Content Output
241
  var webpItems []ParsedFileItem
242
  var originalItems []ParsedFileItem
243
+ var videoItems []ParsedFileItem
244
 
245
  // Sort by name if desired, keeping original logic if preferred. User wants alphabetical "ordenando alfabeticamente" -> Yes we can do that!
246
  for _, it := range items {
 
249
  }
250
  if it.Type == "WEBP" {
251
  webpItems = append(webpItems, it)
252
+ } else if it.Type == "VIDEO" {
253
+ videoItems = append(videoItems, it)
254
  } else {
255
  originalItems = append(originalItems, it)
256
  }
 
262
  sort.Slice(originalItems, func(i, j int) bool {
263
  return originalItems[i].Name < originalItems[j].Name
264
  })
265
+ sort.Slice(videoItems, func(i, j int) bool {
266
+ return videoItems[i].Name < videoItems[j].Name
267
+ })
268
 
269
  var buf bytes.Buffer
270
  buf.WriteString(fmt.Sprintf("==== %s ====\n\n", title))
 
292
  for i, f := range originalItems {
293
  buf.WriteString(fmt.Sprintf("(%d) %s = %s\n", i+1, f.Name, f.LocalLink))
294
  }
295
+ buf.WriteString("\n----------------------------------\n\n")
296
+ }
297
+
298
+ if len(videoItems) > 0 {
299
+ buf.WriteString("---- VIDEO LINKS ----\n\n")
300
+ buf.WriteString("🚀 Para Hugging Face (Público):\n")
301
+ for i, f := range videoItems {
302
+ buf.WriteString(fmt.Sprintf("(%d) %s = %s\n", i+1, f.Name, f.HFLink))
303
+ }
304
+ buf.WriteString("\n🖥 Para tu PC Local (Pruebas):\n")
305
+ for i, f := range videoItems {
306
+ buf.WriteString(fmt.Sprintf("(%d) %s = %s\n", i+1, f.Name, f.LocalLink))
307
+ }
308
  }
309
  buf.WriteString("\n")
310