Files
bbs/internal/server/chanconfig.go
T
Claude 114e56c928 Image boards: an archive of pruned threads
As 4chan's, a thread pruned off a board's last page is archived, not
deleted: off the board's pages and catalog, whole, its files kept,
read-only.  No one replies to it, staff neither (store.AddPost refuses
too, for a reply already on its way); its posts are not deleted by
their passwords (staff still can).  Its page says it is archived in
place of the form and its first post wears a badge.

- /chan/b/archive lists a board's archived threads, the last first;
  /chan/b/archive.json is 4chan's (the numbers, oldest first); an
  archived thread's JSON has archived and archived_on, and boards.json
  is_archived
- [chan] archive_days (3; 0: always) is how long they stay: then they
  are deleted with their files, looked to when a thread is made and
  when the archive or the thread is looked at
- a board's archive setting (bbs chan board set DIR archive no) prunes
  as before, deleting at once; boards have one by default, as do
  those of an older database
- the terminals: a board's thread list has Archive (A), to read them;
  archived threads offer no reply

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFQhReUqUc7F5srk2hViqr
2026-10-14 18:17:57 +00:00

104 lines
3.6 KiB
Go

package server
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
"github.com/Neo-Desktop/bbs-sec/internal/config"
"github.com/Neo-Desktop/bbs-sec/internal/imageboard"
)
// chanSection reads [chan]: how the image boards are run.
func (c *Config) chanSection(s *config.Section) error {
ch := imageboard.Defaults()
ch.Dir = s.String("dir", ch.Dir)
var err error
if ch.MaxFile, err = parseSize(s, "max_file", ch.MaxFile); err != nil {
return err
}
if ch.MaxFile < 1<<10 || ch.MaxFile > 1<<30 {
return fmt.Errorf("max_file: from 1K to 1G")
}
if ch.ThreadWait, err = s.Seconds("thread_wait", int(ch.ThreadWait.Seconds()), 0, 86400); err != nil {
return err
}
if ch.ReplyWait, err = s.Seconds("reply_wait", int(ch.ReplyWait.Seconds()), 0, 86400); err != nil {
return err
}
if ch.MaxComment, err = s.Int("max_comment", ch.MaxComment, 100, 20000); err != nil {
return err
}
if ch.Strip, err = s.Bool("strip_metadata", ch.Strip); err != nil {
return err
}
if ch.Captcha, err = s.Bool("captcha", ch.Captcha); err != nil {
return err
}
if ch.CaptchaLength, err = s.Int("captcha_length", ch.CaptchaLength, imageboard.MinCaptchaLength,
imageboard.MaxCaptchaLength); err != nil {
return err
}
if ch.CaptchaTTL, err = s.Seconds("captcha_lifetime", int(ch.CaptchaTTL.Seconds()), 60, 86400); err != nil {
return err
}
if ch.CaptchaLevel = strings.ToLower(s.String("captcha_level", ch.CaptchaLevel)); imageboard.CaptchaLevels[ch.CaptchaLevel] == (imageboard.CaptchaLevel{}) {
return fmt.Errorf("captcha_level: easy, normal or hard, not %q", ch.CaptchaLevel)
}
if ch.Options, err = s.Bool("options", ch.Options); err != nil {
return err
}
// the country database and its credit are [general]'s unless the
// boards have their own
ch.GeoCredit = s.String("geoip_credit", c.Settings.GeoCredit)
ch.GeoCreditURL = s.String("geoip_credit_url", c.Settings.GeoCreditURL)
if u := ch.GeoCreditURL; u != "" && !strings.HasPrefix(u, "https://") && !strings.HasPrefix(u, "http://") {
return fmt.Errorf("geoip_credit_url: an http(s) address, not %q", u)
}
if ch.GeoIP = s.String("geoip", c.Settings.GeoIP); ch.GeoIP != "" && ch.GeoIP != c.Settings.GeoIP {
if _, err := os.Stat(ch.GeoIP); err != nil {
c.Warnings = append(c.Warnings, fmt.Sprintf("[chan] geoip: %v: no flags until it is there", err))
}
}
// videos' and PDFs' thumbnails: the helpers, if the sysop has them
for _, h := range []struct {
key string
p *string
}{{"ffmpeg", &ch.FFmpeg}, {"pdftoppm", &ch.PDFToPPM}} {
if v := s.String(h.key, ""); v != "" {
path, err := exec.LookPath(v)
if err != nil {
return fmt.Errorf("%s: %w", h.key, err)
}
*h.p = path
}
}
if ch.MaxVideo, err = s.Seconds("max_video", int(ch.MaxVideo.Seconds()), 0, 86400); err != nil {
return err
}
// how long pruned threads stay in their boards' archives (0: always)
days, err := s.Int("archive_days", int(ch.ArchiveFor/(24*time.Hour)), 0, 3650)
if err != nil {
return err
}
ch.ArchiveFor = time.Duration(days) * 24 * time.Hour
// Ruffle's self-hosted package, unpacked: Flash played in the page
if ch.Ruffle = s.String("ruffle", ""); ch.Ruffle != "" {
if _, err := os.Stat(filepath.Join(ch.Ruffle, "ruffle.js")); err != nil {
return fmt.Errorf("ruffle: %s has no ruffle.js (Ruffle's self-hosted package, unpacked): %w", ch.Ruffle, err)
}
}
if ch.Style = s.String("style", ""); ch.Style != "" && !imageboard.KnownStyle(ch.Style) {
var names []string
for _, st := range imageboard.Styles {
names = append(names, st.Name)
}
return fmt.Errorf("style: %q is not one of %s", ch.Style, strings.Join(names, ", "))
}
c.Chan = ch
return nil
}