Compare commits

...
13 Commits
Author SHA1 Message Date
gisle 3ffe1d7816 add config env variables. 2024-08-10 15:00:26 +02:00
gisle 09d31aabac maybe fix comment order?
continuous-integration/drone/push Build is passing
2022-03-04 00:27:28 +01:00
gisle b5c77cf8ca try fix again again again again again.
continuous-integration/drone/push Build is passing
2021-07-26 22:18:31 +02:00
gisle 3045931492 try fix again again again again.
continuous-integration/drone/push Build is passing
2021-07-26 21:43:10 +02:00
gisle 928e643ab7 try fix again again again. 2021-07-26 21:26:53 +02:00
gisle 6b1f34db79 try fix again again.
continuous-integration/drone/push Build is passing
2021-07-26 20:56:46 +02:00
gisle bd27b14a88 try fix again.
continuous-integration/drone/push Build is passing
2021-07-26 20:50:03 +02:00
gisle 4bccdc2ded hopefully fix the bug preventing post deletions sometimes.
continuous-integration/drone/push Build is passing
2021-07-26 20:32:55 +02:00
gisle 67d6161c3b fix characters not updating on edit post and (hopefully) the bug preventing post deletions sometimes.
continuous-integration/drone/push Build is passing
2021-07-26 20:15:51 +02:00
gisle a606b79736 fix prev logs showing current log.
continuous-integration/drone/push Build is passing
2021-04-11 02:14:01 +02:00
gisle 87559997a9 fix comments create/update not applying character name.
continuous-integration/drone/push Build is passing
2021-04-11 01:49:08 +02:00
gisle b641f7d516 fix ts query getting mad at you for quoting a single word. 2021-04-02 20:25:32 +02:00
gisle b117aea7f0 fix ChannelFilter.Logged being ignored in postgres driver.
continuous-integration/drone/push Build is passing
2021-04-02 17:01:15 +02:00
12 changed files with 108 additions and 20 deletions
+15 -1
View File
@@ -10,6 +10,20 @@ steps:
- go generate ./...
- go test -v ./...
# - name: postgres-migrate
# image: golang:1.15
# depends_on: []
# environment:
# DB_CONNECT:
# from_secret: db_connect
# commands:
# - go get -u github.com/pressly/goose/...
# - cd migrations/postgres
# - goose postgres "$DB_CONNECT" up
# when:
# event:
# - tag
- name: docker-release-tag
image: plugins/docker
settings:
@@ -36,4 +50,4 @@ steps:
registry: r.vmaple.dev
when:
event:
- tag
- tag
+4
View File
@@ -38,6 +38,10 @@ func (r *channelRepository) List(ctx context.Context, filter models.ChannelFilte
params.FilterEventName = true
params.EventName = *filter.EventName
}
if filter.Logged != nil {
params.FilterLogged = true
params.Logged = *filter.Logged
}
if filter.Limit > 0 {
params.LimitSize = int32(filter.Limit)
}
+3 -2
View File
@@ -53,7 +53,7 @@ func (r *commentRepository) Insert(ctx context.Context, comment models.Comment)
CharacterID: comment.CharacterID,
Subject: comment.Subject,
Author: comment.Author,
CharacterName: comment.CharacterID,
CharacterName: comment.CharacterName,
Source: comment.Source,
CreatedDate: comment.CreatedDate.UTC(),
FictionalDate: comment.FictionalDate.UTC(),
@@ -73,7 +73,8 @@ func (r *commentRepository) Update(ctx context.Context, comment models.Comment,
Subject: comment.Subject,
Source: comment.Source,
FictionalDate: comment.FictionalDate.UTC(),
CharacterName: comment.ChapterID,
EditedDate: comment.EditedDate.UTC(),
CharacterName: comment.CharacterName,
CharacterID: comment.CharacterID,
ID: comment.ID,
})
@@ -0,0 +1,13 @@
-- +goose Up
-- +goose StatementBegin
ALTER TABLE log_post
DROP CONSTRAINT log_post_log_short_id_position_key,
ADD CONSTRAINT log_post_log_short_id_position_key UNIQUE(log_short_id, position) DEFERRABLE;
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
ALTER TABLE log_post
DROP CONSTRAINT log_post_log_short_id_position_key,
ADD CONSTRAINT log_post_log_short_id_position_key UNIQUE(log_short_id, position);
-- +goose StatementEnd
+16 -5
View File
@@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"errors"
"fmt"
"git.aiterp.net/rpdata/api/database/postgres/psqlcore"
"git.aiterp.net/rpdata/api/internal/generate"
"git.aiterp.net/rpdata/api/models"
@@ -253,9 +254,9 @@ func (r *postRepository) Delete(ctx context.Context, post models.Post) error {
return err
}
err = q.DeletePost(ctx, post.ID)
err = q.MovePost(ctx, psqlcore.MovePostParams{ID: post.ID, Position: -1})
if err != nil {
return err
return fmt.Errorf("pre-delete move failed: %s", err)
}
err = q.ShiftPostsAfter(ctx, psqlcore.ShiftPostsAfterParams{
@@ -264,12 +265,22 @@ func (r *postRepository) Delete(ctx context.Context, post models.Post) error {
FromPosition: int32(post.Position + 1),
})
if err != nil {
return err
return fmt.Errorf("shift failed: %s", err)
}
_ = q.GenerateLogTSVector(ctx, post.LogID)
err = q.DeletePost(ctx, post.ID)
if err != nil {
return fmt.Errorf("delete failed: %s", err)
}
return tx.Commit()
err = tx.Commit()
if err != nil {
return fmt.Errorf("tx commit failed: %s", err)
}
_ = psqlcore.New(r.db).GenerateLogTSVector(ctx, post.LogID)
return nil
}
func (r *postRepository) post(post psqlcore.SelectPostRow) *models.Post {
+2
View File
@@ -14,6 +14,7 @@ UPDATE story_comment
SET subject = @subject,
source = @source,
fictional_date = @fictional_date,
edited_date = @edited_date,
character_name = @character_name,
character_id = @character_id
WHERE id = @id;
@@ -21,6 +22,7 @@ WHERE id = @id;
-- name: SelectComments :many
SELECT * FROM story_comment
WHERE (@chapter_id = '' OR chapter_id = @chapter_id)
ORDER BY fictional_date, created_date
LIMIT NULLIF(@limit_size::INT, 0);
-- name: DeleteComment :exec
+5 -6
View File
@@ -16,16 +16,15 @@ func TSQueryFromSearch(search string) string {
clearQuotes := false
startQuotes := false
if strings.HasPrefix(token, "\"") {
if len(token) > 1 {
token = token[1:]
}
if strings.HasPrefix(token, "\"") && len(token) > 1 {
startQuotes = true
}
if strings.HasSuffix(token, "\"") {
token = token[:len(token)-1]
if !startQuotes {
clearQuotes = true
}
startQuotes = false
clearQuotes = true
}
token := strings.Trim(token, ",.;:()\"")
+1
View File
@@ -13,6 +13,7 @@ func TestTSQueryFromSearch(t *testing.T) {
{`"asari matron" blue`, `(asari<->matron) & blue`},
{`"christmas present" "wrapping paper"`, `(christmas<->present) & (wrapping<->paper)`},
{`stuff`, `stuff`},
{`"stuff"`, `stuff`},
{`"her slowly, rubbing the back of his head awkwardly. "`, `(her<->slowly<->rubbing<->the<->back<->of<->his<->head<->awkwardly)`},
}
+24 -1
View File
@@ -5,6 +5,7 @@ import (
"errors"
"log"
"os"
"strconv"
"strings"
"sync"
@@ -51,6 +52,27 @@ type Wiki struct {
URL string `json:"url" yaml:"url"`
}
func (config *Config) LoadEnv() {
config.Wiki.URL = os.Getenv("RPDATA_WIKI_URL")
config.Space.Enabled = os.Getenv("RPDATA_SPACE_ENABLED") == "true"
config.Space.Host = os.Getenv("RPDATA_SPACE_HOST")
config.Space.AccessKey = os.Getenv("RPDATA_SPACE_ACCESS_KEY")
config.Space.SecretKey = os.Getenv("RPDATA_SPACE_SECRET_KEY")
config.Space.Bucket = os.Getenv("RPDATA_SPACE_BUCKET")
config.Space.MaxSize, _ = strconv.ParseInt(os.Getenv("RPDATA_SPACE_MAX_SIZE"), 10, 64)
config.Space.Root = os.Getenv("RPDATA_SPACE_ROOT")
config.Space.URLRoot = os.Getenv("RPDATA_SPACE_URL_ROOT")
config.Database.Driver = os.Getenv("RPDATA_DATABASE_DRIVER")
config.Database.Host = os.Getenv("RPDATA_DATABASE_HOST")
config.Database.Port, _ = strconv.Atoi(os.Getenv("RPDATA_DATABASE_PORT"))
config.Database.Db = os.Getenv("RPDATA_DATABASE_DB")
config.Database.Username = os.Getenv("RPDATA_DATABASE_USERNAME")
config.Database.Password = os.Getenv("RPDATA_DATABASE_PASSWORD")
config.Database.Mechanism = os.Getenv("RPDATA_DATABASE_MECHANISM")
config.Database.RestoreIDs = os.Getenv("RPDATA_DATABASE_RESTORE_IDS") == "true"
config.Database.SSL = os.Getenv("RPDATA_DATABASE_SSL") == "true"
}
// Load loads config stuff
func (config *Config) Load(filename string) error {
log.Println("Trying to load config from " + filename)
@@ -94,9 +116,10 @@ func Global() Config {
globalMutex.Lock()
if global == nil {
global = &Config{}
global.LoadEnv()
err := global.LoadAny("/etc/aiterp/rpdata.yaml", "/etc/aiterp/rpdata.json", "./config.yaml", "./config.json")
if err != nil {
log.Fatalln(err)
log.Println("No config files were loaded.")
}
}
globalMutex.Unlock()
+1
View File
@@ -32,6 +32,7 @@ func (comment *Comment) ApplyUpdate(update CommentUpdate) {
if update.FictionalDate != nil {
comment.FictionalDate = *update.FictionalDate
}
comment.EditedDate = time.Now()
}
// IsChangeObject is an interface implementation to identify it as a valid
+8 -1
View File
@@ -56,7 +56,7 @@ func (s *AuthService) FindKey(ctx context.Context, id string) (*models.Key, erro
return s.keys.Find(ctx, id)
}
// FindKey finds a key by id.
// FindUser finds a user by id.
func (s *AuthService) FindUser(ctx context.Context, id string) (*models.User, error) {
return s.users.Find(ctx, id)
}
@@ -154,6 +154,13 @@ func (s *AuthService) TokenFromContext(ctx context.Context) *models.Token {
return token
}
// SpinOffContext adds the auth token to a background context.
func (s *AuthService) SpinOffContext(ctx context.Context) context.Context {
token := s.TokenFromContext(ctx)
return context.WithValue(context.Background(), contextKey, token)
}
// RequestWithToken either returns the request, or the request with a new context that
// has the token.
func (s *AuthService) RequestWithToken(r *http.Request) *http.Request {
+16 -4
View File
@@ -484,18 +484,22 @@ func (s *LogService) EditPost(ctx context.Context, id string, update models.Post
return nil, err
}
spinOffCtx := s.authService.SpinOffContext(ctx)
go func() {
l, err := s.logs.Find(context.Background(), post.LogID)
timeout, cancel := context.WithTimeout(spinOffCtx, time.Minute*10)
defer cancel()
l, err := s.logs.Find(timeout, post.LogID)
if err != nil {
return
}
_, err = s.refreshLogCharacters(ctx, *l, nil, false)
s.changeService.Submit(timeout, models.ChangeModelPost, "edit", true, changekeys.Many(l, post), post)
_, err = s.refreshLogCharacters(timeout, *l, nil, false)
if err != nil {
log.Printf("Failed to update characters in log %s: %s", l.ID, err)
}
s.changeService.Submit(ctx, models.ChangeModelPost, "edit", true, changekeys.Many(l, post), post)
}()
return post, nil
@@ -857,6 +861,10 @@ func (s *LogService) NextLogs(ctx context.Context, log *models.Log) ([]*models.L
return logs[i].Date.Before(logs[j].Date)
})
if len(logs) >= 1 && logs[0].ID == log.ID {
logs = logs[1:]
}
return s.findSuggestions(ctx, log, logs)
}
@@ -868,6 +876,10 @@ func (s *LogService) PrevLogs(ctx context.Context, log *models.Log) ([]*models.L
return nil, err
}
if len(logs) >= 1 && logs[0].ID == log.ID {
logs = logs[1:]
}
return s.findSuggestions(ctx, log, logs)
}