summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-10-31 23:20:13 +0200
committerPaul Buetow <paul@buetow.org>2024-10-31 23:20:13 +0200
commit9581ebeb48c48425f2f8f5160455f26dcdc0c550 (patch)
tree997d409962e23cee59d2fbb0a4bc577472dafb20
parentc2b3c4f6e4d40c49d55deb5b696bb3cb8cdde531 (diff)
som stuff
-rw-r--r--cmd/gos/main.go1
-rw-r--r--internal/entry/entry.go2
-rw-r--r--internal/queue/queue.go17
-rw-r--r--internal/run.go8
4 files changed, 14 insertions, 14 deletions
diff --git a/cmd/gos/main.go b/cmd/gos/main.go
index af5a619..060e39f 100644
--- a/cmd/gos/main.go
+++ b/cmd/gos/main.go
@@ -49,6 +49,7 @@ func main() {
OAuth2Browser: *browser,
}
for _, platform := range strings.Split(*platforms, ",") {
+ // TODO: Move parsing to config package.
// E.g. Mastodon:500
parts := strings.Split(platform, ":")
var err error
diff --git a/internal/entry/entry.go b/internal/entry/entry.go
index 040b509..3fd2623 100644
--- a/internal/entry/entry.go
+++ b/internal/entry/entry.go
@@ -156,7 +156,7 @@ func (en Entry) HasTag(tag string) bool {
// Valid tags are: share:foo[,...]
// whereas foo can be a supported plutform such as linkedin, mastodon, etc.
// foo can also be prefixed with - to exclude it. See unit tests for examples.
-func (en Entry) ExcludedByTags(args config.Args, platform string) (bool, error) {
+func (en Entry) PlatformExcluded(args config.Args, platform string) (bool, error) {
s, err := newShareTags(args, en.Path)
return slices.Contains(s.excludes, strings.ToLower(platform)) ||
!slices.Contains(s.includes, strings.ToLower(platform)), err
diff --git a/internal/queue/queue.go b/internal/queue/queue.go
index 80c9d3d..526f43e 100644
--- a/internal/queue/queue.go
+++ b/internal/queue/queue.go
@@ -33,8 +33,7 @@ func queueEntries(args config.Args) error {
// TODO: Use find(...), but refactor with variadic args
ch, err := oi.ReadDirCh(args.GosDir, func(file os.DirEntry) (string, bool) {
filePath := filepath.Join(args.GosDir, file.Name())
- return filePath, slices.Contains(validExtensions, filepath.Ext(file.Name())) &&
- file.Type().IsRegular()
+ return filePath, slices.Contains(validExtensions, filepath.Ext(file.Name())) && file.Type().IsRegular()
})
if err != nil {
return err
@@ -74,20 +73,20 @@ func queuePlatforms(args config.Args) error {
trashDir := filepath.Join(args.GosDir, "db", "trashbin")
for filePath := range ch {
- ent, err := entry.New(filePath)
+ en, err := entry.New(filePath)
if err != nil {
return err
}
for platform := range args.Platforms {
- excluded, err := ent.ExcludedByTags(args, platform)
+ excluded, err := en.PlatformExcluded(args, platform)
if err != nil {
return err
}
if excluded {
- log.Println("Not queueing entry", ent, "to platform", platform, "as it is excluded")
+ log.Println("Not queueing entry", en, "to platform", platform, "as it is excluded")
continue
}
- if err := queuePlatform(ent, args.GosDir, platform); err != nil {
+ if err := queuePlatform(en, args.GosDir, platform); err != nil {
return err
}
}
@@ -96,12 +95,12 @@ func queuePlatforms(args config.Args) error {
}
// Keep queued items in trash for a while.
- trashPath := filepath.Join(trashDir, strings.TrimSuffix(filepath.Base(ent.Path), ".queued")+".trash")
- log.Printf("Trashing %s -> %s", ent.Path, trashPath)
+ trashPath := filepath.Join(trashDir, strings.TrimSuffix(filepath.Base(en.Path), ".queued")+".trash")
+ log.Printf("Trashing %s -> %s", en.Path, trashPath)
if err := oi.EnsureParentDir(trashPath); err != nil {
return err
}
- if err := os.Rename(ent.Path, trashPath); err != nil {
+ if err := os.Rename(en.Path, trashPath); err != nil {
return err
}
}
diff --git a/internal/run.go b/internal/run.go
index 1307d58..ea20643 100644
--- a/internal/run.go
+++ b/internal/run.go
@@ -38,7 +38,7 @@ func Run(ctx context.Context, args config.Args) error {
}
func runPlatform(ctx context.Context, args config.Args, platform string, sizeLimit int) error {
- ent, err := schedule.Run(args, platform)
+ en, err := schedule.Run(args, platform)
switch {
case errors.Is(err, schedule.ErrNothingToSchedule):
log.Println("Nothing to be scheduled for", platform)
@@ -50,7 +50,7 @@ func runPlatform(ctx context.Context, args config.Args, platform string, sizeLim
return err
}
- log.Println("Posting", ent)
+ log.Println("Posting", en)
var postCB func(context.Context, config.Args, int, entry.Entry) error
switch strings.ToLower(platform) {
case "mastodon":
@@ -61,10 +61,10 @@ func runPlatform(ctx context.Context, args config.Args, platform string, sizeLim
log.Fatal("Platform", platform, "(not yet) implemented")
}
- if err := postCB(ctx, args, sizeLimit, ent); err != nil {
+ if err := postCB(ctx, args, sizeLimit, en); err != nil {
return err
}
- if err := ent.MarkPosted(); err != nil {
+ if err := en.MarkPosted(); err != nil {
return err
}