123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- package pages
- import (
- "fmt"
- "strconv"
- "strings"
- "sync"
- core "codeberg.org/vnpower/pixivfe/v2/core/webapi"
- "github.com/gofiber/fiber/v2"
- )
- func ArtworkMultiPage(c *fiber.Ctx) error {
- ids_ := c.Params("ids")
- ids := strings.Split(ids_, ",")
- artworks := make([]*core.Illust, len(ids))
- wg := sync.WaitGroup{}
- // // gofiber/fasthttp's API is trash
- // // i can't replace c.Context() with this
- // // so i guess we will have to wait for network traffic to finish on error
- // ctx, cancel := context.WithCancel(c.Context())
- // defer cancel()
- // c.SetUserContext(ctx)
- var err_global error = nil
- for i, id := range ids {
- if _, err := strconv.Atoi(id); err != nil {
- err_global = fmt.Errorf("Invalid ID: %s", id)
- break
- }
- wg.Add(1)
- go func(i int, id string) {
- defer wg.Done()
- illust, err := core.GetArtworkByID(c, id, false)
- if err != nil {
- artworks[i] = &core.Illust{
- Title: err.Error(), // this might be flaky
- }
- return
- }
- metaDescription := ""
- for _, i := range illust.Tags {
- metaDescription += "#" + i.Name + ", "
- }
- artworks[i] = illust
- }(i, id)
- }
- // if err_global != nil {
- // cancel()
- // }
- wg.Wait()
- if err_global != nil {
- return err_global
- }
- return c.Render("artwork-multi", fiber.Map{
- "Artworks": artworks,
- "Title": fmt.Sprintf("(%d images)", len(artworks)),
- })
- }
|