Compare commits

...
8 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
6 changed files with 61 additions and 10 deletions
@@ -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
+10 -4
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,17 @@ 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)
}
err = q.DeletePost(ctx, post.ID)
if err != nil {
return fmt.Errorf("delete failed: %s", err)
}
err = tx.Commit()
if err != nil {
return err
return fmt.Errorf("tx commit failed: %s", err)
}
_ = psqlcore.New(r.db).GenerateLogTSVector(ctx, post.LogID)
+1
View File
@@ -22,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
+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()
+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 {
+5 -4
View File
@@ -484,15 +484,16 @@ 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
}
timeout, cancel := context.WithTimeout(context.Background(), time.Minute*10)
defer cancel()
s.changeService.Submit(timeout, models.ChangeModelPost, "edit", true, changekeys.Many(l, post), post)
_, err = s.refreshLogCharacters(timeout, *l, nil, false)