mirror of
https://github.com/D-Modem/bbs.git
synced 2026-11-29 01:38:10 -08:00
- FILE_ID.DIZ: an archive uploaded by any way (the BBS, IND$FILE, FTP,
the API, the CLI) is described by its DIZ, kept as the file's longer
description (CP437 decoded, colors and control characters out, at
most 20 lines); its first line that says something is the description
unless the uploader gave one.
- Archives: what is in a ZIP, tar or tar.gz, from a file's details (V,
PF6) and GET /files/{id}/listing.
- New files since the caller's last call (N, PF5) and finding files by
name and descriptions (F, PF10), across the areas they may see; the
API's GET /files?since= and ?q=.
- A batch: files tagged (T, by numbers such as 1 3 5-7, or from a
file's details) download together by YMODEM, ZMODEM or Kermit; a file
counts once the protocol has gone on past it. Frontend.Download takes
a list of files.
- Ratios: [level] ratio and ratio_free (files downloadable for each
upload, and before the ratio counts), checked with the day's limit for
a whole batch. Users' lifetime downloads and uploads are counted.
The store gains a {plain} token: PostgreSQL's LIKE refuses the
case-insensitive collation of {name} columns. Tested on SQLite,
PostgreSQL, MySQL and MariaDB.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFQhReUqUc7F5srk2hViqr
77 lines
2.2 KiB
Go
77 lines
2.2 KiB
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/Neo-Desktop/bbs-sec/internal/bbs"
|
|
"github.com/Neo-Desktop/bbs-sec/internal/config"
|
|
)
|
|
|
|
// levelSections reads [level N] and [general]'s new_user_level and
|
|
// validated_level.
|
|
func (c *Config) levelSections(cf *config.File) error {
|
|
s := &c.Settings
|
|
g := cf.Get("general", "")
|
|
var err error
|
|
if s.NewUserLevel, err = g.Int("new_user_level", s.NewUserLevel, 0, bbs.MaxLevel); err != nil {
|
|
return fmt.Errorf("[general] %w", err)
|
|
}
|
|
if s.ValidatedLevel, err = g.Int("validated_level", max(s.ValidatedLevel, s.NewUserLevel), 0, bbs.MaxLevel); err != nil {
|
|
return fmt.Errorf("[general] %w", err)
|
|
}
|
|
if s.ValidatedLevel < s.NewUserLevel {
|
|
return fmt.Errorf("[general] validated_level (%d) is below new_user_level (%d)", s.ValidatedLevel, s.NewUserLevel)
|
|
}
|
|
seen := map[int]bool{}
|
|
for _, sec := range cf.All("level") {
|
|
l, err := level(sec)
|
|
if err != nil {
|
|
return fmt.Errorf("[level %s] %w", sec.Name, err)
|
|
}
|
|
if seen[l.Num] {
|
|
return fmt.Errorf("[level %s] given twice", sec.Name)
|
|
}
|
|
seen[l.Num] = true
|
|
s.Levels = append(s.Levels, l)
|
|
}
|
|
bbs.SortLevels(s.Levels)
|
|
if len(s.Levels) > 0 && s.Levels[0].Num > 0 {
|
|
c.Warnings = append(c.Warnings, fmt.Sprintf("levels under %d have no [level]: no limits", s.Levels[0].Num))
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func level(sec *config.Section) (bbs.Level, error) {
|
|
n, err := strconv.Atoi(sec.Name)
|
|
if err != nil || n < 0 || n > bbs.MaxLevel {
|
|
return bbs.Level{}, fmt.Errorf("a level is a number, 0 to %d: [level 20]", bbs.MaxLevel)
|
|
}
|
|
l := bbs.AllowAll(n, sec.String("name", "Level "+sec.Name))
|
|
mins, err := sec.Int("time", 0, 0, 24*60)
|
|
if err != nil {
|
|
return l, err
|
|
}
|
|
l.Time = time.Duration(mins) * time.Minute
|
|
if l.Downloads, err = sec.Int("downloads", 0, 0, 100000); err != nil {
|
|
return l, err
|
|
}
|
|
if l.Ratio, err = sec.Int("ratio", 0, 0, 1000); err != nil {
|
|
return l, err
|
|
}
|
|
if l.RatioFree, err = sec.Int("ratio_free", 0, 0, 100000); err != nil {
|
|
return l, err
|
|
}
|
|
for _, b := range []struct {
|
|
key string
|
|
p *bool
|
|
}{{"post", &l.Post}, {"mail", &l.Mail}, {"chat", &l.Chat}, {"page", &l.Page},
|
|
{"download", &l.Download}, {"upload", &l.Upload}, {"doors", &l.Doors}} {
|
|
if *b.p, err = sec.Bool(b.key, true); err != nil {
|
|
return l, err
|
|
}
|
|
}
|
|
return l, nil
|
|
}
|