Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
947765884e | ||
|
|
ffec008820 | ||
|
|
138b3e3eab | ||
|
|
929abfdbe4 | ||
|
|
a8cd595876 | ||
|
|
9ed3b32b42 | ||
|
|
6bae52d652 | ||
|
|
cee370c2ac | ||
|
|
9affdbd20e | ||
|
|
cf545cde3b | ||
|
|
b414cf118f | ||
|
|
4979b02104 |
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
"git.aiterp.net/rpdata/api/internal/config"
|
||||
"git.aiterp.net/rpdata/api/internal/store"
|
||||
"git.aiterp.net/rpdata/api/model/file"
|
||||
"git.aiterp.net/rpdata/api/models/files"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -33,7 +33,7 @@ func main() {
|
||||
store.Init()
|
||||
|
||||
for _, info := range data.Query.Allimages {
|
||||
existing, err := file.FindName("wiki", info.Name, info.User)
|
||||
existing, err := files.FindName("wiki", info.Name, info.User)
|
||||
if err == nil && existing.ID != "" {
|
||||
log.Println("Skipping", info.Name, "because it already exists")
|
||||
continue
|
||||
@@ -45,7 +45,7 @@ func main() {
|
||||
continue
|
||||
}
|
||||
|
||||
file, err := file.Insert(info.Name, "wiki", info.Mime, info.User, ts, info.Size, info.URL)
|
||||
file, err := files.Insert(info.Name, "wiki", info.Mime, info.User, ts, info.Size, info.URL)
|
||||
if err != nil {
|
||||
log.Println("Skipping", info.Name, "error:", err)
|
||||
continue
|
||||
|
||||
@@ -49,6 +49,16 @@ models:
|
||||
model: git.aiterp.net/rpdata/api/models.File
|
||||
FilesFilter:
|
||||
model: git.aiterp.net/rpdata/api/models/files.Filter
|
||||
Change:
|
||||
model: git.aiterp.net/rpdata/api/models.Change
|
||||
ChangeModel:
|
||||
model: git.aiterp.net/rpdata/api/models.ChangeModel
|
||||
ChangeKey:
|
||||
model: git.aiterp.net/rpdata/api/models.ChangeKey
|
||||
ChangeKeyInput: # It's the same as ChangeKey
|
||||
model: git.aiterp.net/rpdata/api/models.ChangeKey
|
||||
ChangesFilter:
|
||||
model: git.aiterp.net/rpdata/api/models/changes.Filter
|
||||
Token:
|
||||
model: git.aiterp.net/rpdata/api/models.Token
|
||||
User:
|
||||
|
||||
@@ -42,6 +42,10 @@ func (r *rootResolver) File() FileResolver {
|
||||
return &types.FileResolver
|
||||
}
|
||||
|
||||
func (r *rootResolver) Change() ChangeResolver {
|
||||
return &types.ChangeResolver
|
||||
}
|
||||
|
||||
func (r *rootResolver) Token() TokenResolver {
|
||||
return &types.TokenResolver
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
"git.aiterp.net/rpdata/api/models/changes"
|
||||
)
|
||||
|
||||
/// Queries
|
||||
|
||||
func (r *resolver) Changes(ctx context.Context, filter *changes.Filter) ([]models.Change, error) {
|
||||
return changes.List(filter)
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"git.aiterp.net/rpdata/api/graph2/input"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
"git.aiterp.net/rpdata/api/models/changekeys"
|
||||
"git.aiterp.net/rpdata/api/models/changes"
|
||||
"git.aiterp.net/rpdata/api/models/channels"
|
||||
)
|
||||
@@ -51,7 +52,7 @@ func (r *mutationResolver) AddChannel(ctx context.Context, input input.ChannelAd
|
||||
return models.Channel{}, errors.New("Failed to add channel: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Channel", "add", token.UserID, channel)
|
||||
go changes.Submit("Channel", "add", token.UserID, true, changekeys.Listed(channel), channel)
|
||||
|
||||
return channel, nil
|
||||
}
|
||||
@@ -72,7 +73,7 @@ func (r *mutationResolver) EditChannel(ctx context.Context, input input.ChannelE
|
||||
return models.Channel{}, errors.New("Failed to edit channel: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Channel", "edit", token.UserID, channel)
|
||||
go changes.Submit("Channel", "edit", token.UserID, true, changekeys.Listed(channel), channel)
|
||||
|
||||
return channel, nil
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models/changekeys"
|
||||
"git.aiterp.net/rpdata/api/models/changes"
|
||||
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/models/stories"
|
||||
|
||||
@@ -45,7 +48,58 @@ func (r *mutationResolver) AddChapter(ctx context.Context, input input.ChapterAd
|
||||
return models.Chapter{}, errors.New("Story is not open")
|
||||
}
|
||||
|
||||
return chapters.Add(story, input.Title, author, input.Source, time.Now(), input.FictionalDate)
|
||||
chapter, err := chapters.Add(story, input.Title, author, input.Source, time.Now(), input.FictionalDate)
|
||||
if err != nil {
|
||||
return models.Chapter{}, errors.New("Failed to create chapter: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Chapter", "add", token.UserID, story.Listed, changekeys.Listed(story, chapter), story, chapter)
|
||||
|
||||
return chapter, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) MoveChapter(ctx context.Context, input input.ChapterMoveInput) (models.Chapter, error) {
|
||||
chapter, err := chapters.FindID(input.ID)
|
||||
if err != nil {
|
||||
return models.Chapter{}, errors.New("Chapter not found")
|
||||
}
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Authenticated() || !token.PermittedUser(chapter.Author, "member", "chapter.move") {
|
||||
return models.Chapter{}, errors.New("You are not allowed to move this chapter")
|
||||
}
|
||||
|
||||
target, err := stories.FindID(input.StoryID)
|
||||
if err != nil {
|
||||
return models.Chapter{}, errors.New("Target story not found")
|
||||
}
|
||||
|
||||
if !target.Open && !token.PermittedUser(target.Author, "member", "chapter.move") {
|
||||
return models.Chapter{}, errors.New("You are not permitted to move chapters to this story")
|
||||
}
|
||||
|
||||
oldStoryID := chapter.StoryID
|
||||
chapter, err = chapters.Move(chapter, target)
|
||||
if err != nil {
|
||||
return models.Chapter{}, errors.New("Failed to move chapter: " + err.Error())
|
||||
}
|
||||
|
||||
go func() {
|
||||
story, err := stories.FindID(chapter.StoryID)
|
||||
if err != nil {
|
||||
story.ID = chapter.StoryID
|
||||
}
|
||||
|
||||
oldStory, err := stories.FindID(oldStoryID)
|
||||
if err != nil {
|
||||
oldStory.ID = oldStoryID
|
||||
}
|
||||
|
||||
changes.Submit("Chapter", "move-out", chapter.Author, oldStory.Listed, changekeys.Many(oldStory, chapter), chapter)
|
||||
changes.Submit("Chapter", "move-in", token.UserID, story.Listed, changekeys.Listed(story, chapter), story, chapter)
|
||||
}()
|
||||
|
||||
return chapter, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) EditChapter(ctx context.Context, input input.ChapterEditInput) (models.Chapter, error) {
|
||||
@@ -63,7 +117,21 @@ func (r *mutationResolver) EditChapter(ctx context.Context, input input.ChapterE
|
||||
input.FictionalDate = &time.Time{}
|
||||
}
|
||||
|
||||
return chapters.Edit(chapter, input.Title, input.Source, input.FictionalDate)
|
||||
chapter, err = chapters.Edit(chapter, input.Title, input.Source, input.FictionalDate)
|
||||
if err != nil {
|
||||
return models.Chapter{}, errors.New("Failed to edit chapter: " + err.Error())
|
||||
}
|
||||
|
||||
go func() {
|
||||
story, err := stories.FindID(chapter.StoryID)
|
||||
if err != nil {
|
||||
story.ID = chapter.StoryID
|
||||
}
|
||||
|
||||
changes.Submit("Chapter", "edit", token.UserID, story.Listed, changekeys.Many(story, chapter), chapter)
|
||||
}()
|
||||
|
||||
return chapter, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) RemoveChapter(ctx context.Context, input input.ChapterRemoveInput) (models.Chapter, error) {
|
||||
@@ -77,5 +145,19 @@ func (r *mutationResolver) RemoveChapter(ctx context.Context, input input.Chapte
|
||||
return models.Chapter{}, errors.New("Unauthorized")
|
||||
}
|
||||
|
||||
return chapters.Remove(chapter)
|
||||
chapter, err = chapters.Remove(chapter)
|
||||
if err != nil {
|
||||
return models.Chapter{}, errors.New("Failed to remove chapter: " + err.Error())
|
||||
}
|
||||
|
||||
go func() {
|
||||
story, err := stories.FindID(chapter.StoryID)
|
||||
if err != nil {
|
||||
story.ID = chapter.StoryID
|
||||
}
|
||||
|
||||
changes.Submit("Chapter", "remove", token.UserID, story.Listed, changekeys.Many(story, chapter), chapter)
|
||||
}()
|
||||
|
||||
return chapter, nil
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"git.aiterp.net/rpdata/api/graph2/input"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
"git.aiterp.net/rpdata/api/models/changekeys"
|
||||
"git.aiterp.net/rpdata/api/models/changes"
|
||||
"git.aiterp.net/rpdata/api/models/characters"
|
||||
"git.aiterp.net/rpdata/api/models/logs"
|
||||
@@ -68,7 +69,7 @@ func (r *mutationResolver) AddCharacter(ctx context.Context, input input.Charact
|
||||
return models.Character{}, errors.New("Adding character failed: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Character", "add", token.UserID, character)
|
||||
go changes.Submit("Character", "add", token.UserID, true, changekeys.Listed(character), character)
|
||||
|
||||
return character, nil
|
||||
}
|
||||
@@ -96,7 +97,7 @@ func (r *mutationResolver) AddCharacterNick(ctx context.Context, input input.Cha
|
||||
}
|
||||
|
||||
go logs.ScheduleFullUpdate()
|
||||
go changes.Submit("Character", "edit", token.UserID, character)
|
||||
go changes.Submit("Character", "edit", token.UserID, true, changekeys.Listed(character), character)
|
||||
|
||||
return character, nil
|
||||
}
|
||||
@@ -118,7 +119,7 @@ func (r *mutationResolver) RemoveCharacterNick(ctx context.Context, input input.
|
||||
}
|
||||
|
||||
go logs.ScheduleFullUpdate()
|
||||
go changes.Submit("Character", "edit", token.UserID, character)
|
||||
go changes.Submit("Character", "edit", token.UserID, true, changekeys.Listed(character), character)
|
||||
|
||||
return character, nil
|
||||
}
|
||||
@@ -146,7 +147,7 @@ func (r *mutationResolver) EditCharacter(ctx context.Context, input input.Charac
|
||||
return models.Character{}, errors.New("Failed to edit character: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Character", "edit", token.UserID, character)
|
||||
go changes.Submit("Character", "edit", token.UserID, true, changekeys.Listed(character), character)
|
||||
|
||||
return character, nil
|
||||
}
|
||||
@@ -167,7 +168,7 @@ func (r *mutationResolver) RemoveCharacter(ctx context.Context, input input.Char
|
||||
return models.Character{}, errors.New("Failed to remove character: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Character", "remove", token.UserID, character)
|
||||
go changes.Submit("Character", "remove", token.UserID, true, changekeys.Listed(character), character)
|
||||
|
||||
return character, nil
|
||||
}
|
||||
|
||||
+17
-3
@@ -5,10 +5,13 @@ import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models/channels"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graph2/input"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/internal/loader"
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
"git.aiterp.net/rpdata/api/models/changekeys"
|
||||
"git.aiterp.net/rpdata/api/models/changes"
|
||||
"git.aiterp.net/rpdata/api/models/logs"
|
||||
"github.com/99designs/gqlgen/graphql"
|
||||
@@ -72,12 +75,23 @@ func (r *mutationResolver) AddLog(ctx context.Context, input input.LogAddInput)
|
||||
description = *input.Description
|
||||
}
|
||||
|
||||
existingChannel, _ := channels.FindName(input.Channel)
|
||||
|
||||
log, err := logs.Add(input.Date, input.Channel, title, event, description, open)
|
||||
if !token.Authenticated() || !token.Permitted("log.add") {
|
||||
return models.Log{}, errors.New("Failed to create log: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Log", "add", token.UserID, log)
|
||||
go func() {
|
||||
if existingChannel.Name == "" {
|
||||
channel, err := channels.FindName(input.Channel)
|
||||
if err == nil {
|
||||
changes.Submit("Channel", "add", token.UserID, true, changekeys.Listed(channel), channel)
|
||||
}
|
||||
}
|
||||
|
||||
changes.Submit("Log", "add", token.UserID, true, changekeys.Listed(log), log)
|
||||
}()
|
||||
|
||||
return log, nil
|
||||
}
|
||||
@@ -98,7 +112,7 @@ func (r *mutationResolver) EditLog(ctx context.Context, input input.LogEditInput
|
||||
return models.Log{}, errors.New("Failed to edit log: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Log", "edit", token.UserID, log)
|
||||
go changes.Submit("Log", "edit", token.UserID, true, changekeys.Listed(log), log)
|
||||
|
||||
return log, nil
|
||||
}
|
||||
@@ -119,7 +133,7 @@ func (r *mutationResolver) RemoveLog(ctx context.Context, input input.LogRemoveI
|
||||
return models.Log{}, errors.New("Failed to remove log: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Log", "remove", token.UserID, log)
|
||||
go changes.Submit("Log", "remove", token.UserID, true, changekeys.Listed(log), log)
|
||||
|
||||
return log, nil
|
||||
}
|
||||
|
||||
+19
-8
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models/changekeys"
|
||||
"git.aiterp.net/rpdata/api/models/changes"
|
||||
"git.aiterp.net/rpdata/api/models/logs"
|
||||
|
||||
@@ -59,7 +60,7 @@ func (r *mutationResolver) AddPost(ctx context.Context, input input.PostAddInput
|
||||
}
|
||||
|
||||
go logs.UpdateCharacters(log)
|
||||
go changes.Submit("Post", "add", token.UserID, post)
|
||||
go changes.Submit("Post", "add", token.UserID, true, changekeys.Many(log, post), post)
|
||||
|
||||
return post, nil
|
||||
}
|
||||
@@ -91,7 +92,14 @@ func (r *mutationResolver) EditPost(ctx context.Context, input input.PostEditInp
|
||||
return models.Post{}, errors.New("Adding post failed: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Post", "edit", token.UserID, post)
|
||||
go func() {
|
||||
log, err := logs.FindID(post.LogID)
|
||||
if err != nil {
|
||||
log = models.Log{ID: post.LogID}
|
||||
}
|
||||
|
||||
changes.Submit("Post", "edit", token.UserID, true, changekeys.Many(log, post), post)
|
||||
}()
|
||||
|
||||
return post, nil
|
||||
}
|
||||
@@ -112,11 +120,14 @@ func (r *mutationResolver) MovePost(ctx context.Context, input input.PostMoveInp
|
||||
return nil, errors.New("Moving posts failed: " + err.Error())
|
||||
}
|
||||
|
||||
posts2 := make([]interface{}, len(posts))
|
||||
for i := range posts {
|
||||
posts2[i] = posts[i]
|
||||
}
|
||||
go changes.Submit("Post", "move", token.UserID, posts2...)
|
||||
go func() {
|
||||
log, err := logs.FindID(post.LogID)
|
||||
if err != nil {
|
||||
log = models.Log{ID: post.LogID}
|
||||
}
|
||||
|
||||
changes.Submit("Post", "move", token.UserID, true, changekeys.Many(log, posts), posts)
|
||||
}()
|
||||
|
||||
return posts, nil
|
||||
}
|
||||
@@ -144,8 +155,8 @@ func (r *mutationResolver) RemovePost(ctx context.Context, input input.PostRemov
|
||||
}
|
||||
|
||||
logs.UpdateCharacters(log)
|
||||
changes.Submit("Post", "remove", token.UserID, true, changekeys.Many(log, post), post)
|
||||
}()
|
||||
go changes.Submit("Post", "remove", token.UserID, post)
|
||||
|
||||
return post, nil
|
||||
}
|
||||
|
||||
+37
-4
@@ -5,6 +5,9 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models/changekeys"
|
||||
"git.aiterp.net/rpdata/api/models/changes"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graph2/input"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
@@ -58,7 +61,14 @@ func (r *mutationResolver) AddStory(ctx context.Context, input input.StoryAddInp
|
||||
listed := input.Listed != nil && *input.Listed
|
||||
open := input.Open != nil && *input.Open
|
||||
|
||||
return stories.Add(input.Name, author, input.Category, listed, open, input.Tags, time.Now(), fictionalDate)
|
||||
story, err := stories.Add(input.Name, author, input.Category, listed, open, input.Tags, time.Now(), fictionalDate)
|
||||
if err != nil {
|
||||
return models.Story{}, errors.New("Failed to add story: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Story", "add", token.UserID, story.Listed, changekeys.Listed(story), story)
|
||||
|
||||
return story, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) AddStoryTag(ctx context.Context, input input.StoryTagAddInput) (models.Story, error) {
|
||||
@@ -73,7 +83,14 @@ func (r *mutationResolver) AddStoryTag(ctx context.Context, input input.StoryTag
|
||||
return models.Story{}, errors.New("You are not permitted to edit this story")
|
||||
}
|
||||
|
||||
return stories.AddTag(story, input.Tag)
|
||||
story, err = stories.AddTag(story, input.Tag)
|
||||
if err != nil {
|
||||
return models.Story{}, errors.New("Failed to add story: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Story", "tag", token.UserID, story.Listed, changekeys.Listed(story), story, input.Tag)
|
||||
|
||||
return story, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) RemoveStoryTag(ctx context.Context, input input.StoryTagRemoveInput) (models.Story, error) {
|
||||
@@ -88,7 +105,14 @@ func (r *mutationResolver) RemoveStoryTag(ctx context.Context, input input.Story
|
||||
return models.Story{}, errors.New("You are not permitted to edit this story")
|
||||
}
|
||||
|
||||
return stories.RemoveTag(story, input.Tag)
|
||||
story, err = stories.RemoveTag(story, input.Tag)
|
||||
if err != nil {
|
||||
return models.Story{}, errors.New("Failed to add story: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Story", "untag", token.UserID, story.Listed, changekeys.Listed(story), story, input.Tag)
|
||||
|
||||
return story, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) EditStory(ctx context.Context, input input.StoryEditInput) (models.Story, error) {
|
||||
@@ -107,7 +131,14 @@ func (r *mutationResolver) EditStory(ctx context.Context, input input.StoryEditI
|
||||
input.FictionalDate = &time.Time{}
|
||||
}
|
||||
|
||||
return stories.Edit(story, input.Name, input.Category, input.Listed, input.Open, input.FictionalDate)
|
||||
story, err = stories.Edit(story, input.Name, input.Category, input.Listed, input.Open, input.FictionalDate)
|
||||
if err != nil {
|
||||
return models.Story{}, errors.New("Failed to add story: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Story", "edit", token.UserID, story.Listed, changekeys.Listed(story), story)
|
||||
|
||||
return story, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) RemoveStory(ctx context.Context, input input.StoryRemoveInput) (models.Story, error) {
|
||||
@@ -132,5 +163,7 @@ func (r *mutationResolver) RemoveStory(ctx context.Context, input input.StoryRem
|
||||
return models.Story{}, errors.New("Failed to remove chapters, but story is removed: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Story", "remove", token.UserID, story.Listed, changekeys.Listed(story), story)
|
||||
|
||||
return story, nil
|
||||
}
|
||||
|
||||
@@ -54,6 +54,10 @@ type Query {
|
||||
files(filter: FilesFilter): [File!]!
|
||||
|
||||
|
||||
# Find changes
|
||||
changes(filter: ChangesFilter): [Change!]!
|
||||
|
||||
|
||||
# Get information about the token, useful for debugging.
|
||||
token: Token!
|
||||
}
|
||||
@@ -81,6 +85,9 @@ type Mutation {
|
||||
# Edit a chapter
|
||||
editChapter(input: ChapterEditInput!): Chapter!
|
||||
|
||||
# Move a chapter
|
||||
moveChapter(input: ChapterMoveInput!): Chapter!
|
||||
|
||||
# Remove a chapter
|
||||
removeChapter(input: ChapterRemoveInput!): Chapter!
|
||||
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
"""
|
||||
A change represents a a change in the history.
|
||||
"""
|
||||
type Change {
|
||||
"A unique ID of the change."
|
||||
id: String!
|
||||
|
||||
"The model of the changed object."
|
||||
model: ChangeModel!
|
||||
|
||||
"The operation performed."
|
||||
op: String!
|
||||
|
||||
"The author that performed the change."
|
||||
author: String!
|
||||
|
||||
"Whether the change will be listed without a matching key."
|
||||
listed: Boolean!
|
||||
|
||||
"The keys indexing this change."
|
||||
keys: [ChangeKey!]!
|
||||
|
||||
"The date when the change happened."
|
||||
date: Date
|
||||
|
||||
"The changed objects."
|
||||
objects: [ChangeObject!]!
|
||||
}
|
||||
|
||||
union ChangeObject = Character | Channel | Log | Post | Story | Tag | Chapter
|
||||
|
||||
"""
|
||||
A change key is a key associated with a change, used for filtering
|
||||
and subscription. A log post edit has keys for both the log and post,
|
||||
making it suitable to use it to patch an active log file.
|
||||
"""
|
||||
type ChangeKey {
|
||||
"The model the key is for."
|
||||
model: ChangeModel!
|
||||
|
||||
"The model's id, or * if it's a key indicating a model list should be updated."
|
||||
id: String!
|
||||
}
|
||||
|
||||
"""
|
||||
See ChangeKey
|
||||
"""
|
||||
input ChangeKeyInput {
|
||||
"The model the key is for."
|
||||
model: ChangeModel!
|
||||
|
||||
"The model's id, or * if it's a key indicating a model list should be updated."
|
||||
id: String!
|
||||
}
|
||||
|
||||
"""
|
||||
A model related to the change.
|
||||
"""
|
||||
enum ChangeModel {
|
||||
Character
|
||||
Channel
|
||||
Log
|
||||
Post
|
||||
Story
|
||||
Tag
|
||||
Chapter
|
||||
}
|
||||
|
||||
"""
|
||||
Optional filter for the changes query.
|
||||
"""
|
||||
input ChangesFilter {
|
||||
"The keys to query for."
|
||||
keys: [ChangeKeyInput!]
|
||||
|
||||
"Only show changes more recent than this date."
|
||||
earliestDate: Date
|
||||
|
||||
"Limit the amount of results."
|
||||
limit: Int
|
||||
}
|
||||
@@ -61,6 +61,15 @@ input ChapterEditInput {
|
||||
clearFictionalDate: Boolean
|
||||
}
|
||||
|
||||
# Input for moveChapter mutation
|
||||
input ChapterMoveInput {
|
||||
# The chapter to move
|
||||
id: String!
|
||||
|
||||
# The story to move it to
|
||||
storyId: String!
|
||||
}
|
||||
|
||||
# Input for removeChapter mutation
|
||||
input ChapterRemoveInput {
|
||||
# The chapter to remove
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graph2/input"
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
)
|
||||
|
||||
type changeResolver struct{}
|
||||
|
||||
func (r *changeResolver) Objects(ctx context.Context, obj *models.Change) ([]input.ChangeObject, error) {
|
||||
objects := obj.Objects()
|
||||
|
||||
results := make([]input.ChangeObject, len(objects))
|
||||
for i := range objects {
|
||||
results[i] = objects[i]
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
// ChangeResolver is a resolver
|
||||
var ChangeResolver changeResolver
|
||||
@@ -1,59 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/channel"
|
||||
)
|
||||
|
||||
// ChannelAddArgs is input for the addChannel mutation
|
||||
type ChannelAddArgs struct {
|
||||
Input *struct {
|
||||
Name string
|
||||
Logged *bool
|
||||
Hub *bool
|
||||
EventName *string
|
||||
LocationName *string
|
||||
}
|
||||
}
|
||||
|
||||
// AddChannel resolves the addChannel mutation
|
||||
func (r *MutationResolver) AddChannel(ctx context.Context, args *ChannelAddArgs) (*types.ChannelResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("channel.add") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
logged := input.Logged != nil && *input.Logged
|
||||
|
||||
hub := input.Hub != nil && *input.Hub
|
||||
|
||||
eventName := ""
|
||||
if input.EventName != nil {
|
||||
eventName = *input.EventName
|
||||
}
|
||||
|
||||
locationName := ""
|
||||
if input.LocationName != nil {
|
||||
locationName = *input.LocationName
|
||||
}
|
||||
|
||||
channel, err := channel.New(input.Name, logged, hub, eventName, locationName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Channel", "add", token.UserID, channel.Name, map[string]interface{}{
|
||||
"logged": channel.Logged,
|
||||
"hub": channel.Hub,
|
||||
"location": input.LocationName,
|
||||
"event": input.EventName,
|
||||
})
|
||||
|
||||
return &types.ChannelResolver{C: channel}, nil
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// AddChapterArgs is args for the addChapter mutation
|
||||
type AddChapterArgs struct {
|
||||
Input *struct {
|
||||
StoryID string
|
||||
Title string
|
||||
Author *string
|
||||
Source string
|
||||
FictionalDate *string
|
||||
}
|
||||
}
|
||||
|
||||
// AddChapter resolves the addChapter mutation
|
||||
func (r *MutationResolver) AddChapter(ctx context.Context, args *AddChapterArgs) (*types.ChapterResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member", "chapter.add") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
story, err := story.FindID(input.StoryID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
author := token.UserID
|
||||
if input.Author != nil {
|
||||
author = *input.Author
|
||||
|
||||
if token.UserID != author && !token.Permitted("chapter.add") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
}
|
||||
|
||||
fictionalDate := time.Time{}
|
||||
if input.FictionalDate != nil {
|
||||
fictionalDate, err = time.Parse(time.RFC3339Nano, *input.FictionalDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
chapter, err := story.AddChapter(input.Title, author, input.Source, time.Now(), fictionalDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Chapter", "add", token.UserID, chapter.ID, map[string]interface{}{
|
||||
"title": input.Title,
|
||||
"author": author,
|
||||
"fictionalDate": fictionalDate,
|
||||
})
|
||||
|
||||
return &types.ChapterResolver{C: chapter}, nil
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/character"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// AddCharacterInput is args for the addCharacter mutation
|
||||
type AddCharacterInput struct {
|
||||
Nick string
|
||||
Name string
|
||||
ShortName *string
|
||||
Author *string
|
||||
Description *string
|
||||
}
|
||||
|
||||
// AddCharacter resolves the addCharacter mutation
|
||||
func (r *MutationResolver) AddCharacter(ctx context.Context, args struct{ Input *AddCharacterInput }) (*types.CharacterResolver, error) {
|
||||
input := args.Input
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member", "character.add") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
nick := input.Nick
|
||||
|
||||
name := input.Name
|
||||
|
||||
shortName := ""
|
||||
if input.ShortName != nil {
|
||||
shortName = *input.ShortName
|
||||
} else {
|
||||
shortName = strings.SplitN(input.Name, " ", 2)[0]
|
||||
}
|
||||
|
||||
author := token.UserID
|
||||
if input.Author != nil {
|
||||
author = *input.Author
|
||||
|
||||
if author != token.UserID && !token.Permitted("character.add") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
}
|
||||
|
||||
description := ""
|
||||
if input.Description != nil {
|
||||
description = *input.Description
|
||||
}
|
||||
|
||||
character, err := character.New(nick, name, shortName, author, description)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Character", "add", token.UserID, character.ID, map[string]interface{}{
|
||||
"name": character.Name,
|
||||
"nick": character.Nicks[0],
|
||||
"author": character.Author,
|
||||
})
|
||||
|
||||
log.ScheduleCharacterUpdate()
|
||||
|
||||
return &types.CharacterResolver{C: character}, nil
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/character"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// AddCharacterNickInput is args for the addCharacterNick mutation
|
||||
type AddCharacterNickInput struct {
|
||||
ID string
|
||||
Nick string
|
||||
}
|
||||
|
||||
// AddCharacterNick resolves the addCharacterNick mutation
|
||||
func (r *MutationResolver) AddCharacterNick(ctx context.Context, args struct{ Input *AddCharacterNickInput }) (*types.CharacterResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
character, err := character.FindID(input.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if character.Author != token.UserID && !token.Permitted("character.edit") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
|
||||
err = character.AddNick(input.Nick)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Character", "add.nick", token.UserID, character.ID, map[string]interface{}{
|
||||
"nick": input.Nick,
|
||||
})
|
||||
|
||||
log.ScheduleCharacterUpdate()
|
||||
|
||||
return &types.CharacterResolver{C: character}, nil
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// LogAddArgs is args for the addLog mutation
|
||||
type LogAddArgs struct {
|
||||
Input *struct {
|
||||
Date string
|
||||
Channel string
|
||||
Title *string
|
||||
Open *bool
|
||||
Event *string
|
||||
Description *string
|
||||
}
|
||||
}
|
||||
|
||||
// AddLog resolves the addLog mutation
|
||||
func (r *MutationResolver) AddLog(ctx context.Context, args *LogAddArgs) (*types.LogResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("log.add") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
date, err := time.Parse(time.RFC3339Nano, args.Input.Date)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
title := ""
|
||||
if input.Title != nil {
|
||||
title = *input.Title
|
||||
}
|
||||
|
||||
event := ""
|
||||
if input.Event != nil {
|
||||
event = *input.Event
|
||||
}
|
||||
|
||||
description := ""
|
||||
if input.Description != nil {
|
||||
description = *input.Description
|
||||
}
|
||||
|
||||
open := input.Open != nil && *input.Open == true
|
||||
|
||||
log, err := log.New(date, input.Channel, title, event, description, open)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Log", "add", token.UserID, log.ID, map[string]interface{}{
|
||||
"channel": log.Channel,
|
||||
"title": log.Title,
|
||||
"event": log.Event,
|
||||
"description": log.Description,
|
||||
"open": log.Open,
|
||||
})
|
||||
|
||||
return &types.LogResolver{L: log}, nil
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// PostAddArgs is args for addPost mutation
|
||||
type PostAddArgs struct {
|
||||
Input *struct {
|
||||
LogID string
|
||||
Time string
|
||||
Kind string
|
||||
Nick string
|
||||
Text string
|
||||
}
|
||||
}
|
||||
|
||||
// AddPost resolves the addPost mutation
|
||||
func (r *MutationResolver) AddPost(ctx context.Context, args *PostAddArgs) (*types.PostResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("post.add") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
postTime, err := time.Parse(time.RFC3339Nano, input.Time)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log, err := log.FindID(input.LogID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
post, err := log.NewPost(postTime, input.Kind, input.Nick, input.Text)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Post", "add", token.UserID, post.ID, map[string]interface{}{
|
||||
"logId": post.LogID,
|
||||
"time": post.Time,
|
||||
"kind": post.Kind,
|
||||
"nick": post.Nick,
|
||||
"text": post.Text,
|
||||
"position": post.Position,
|
||||
})
|
||||
|
||||
go log.UpdateCharacters()
|
||||
|
||||
return &types.PostResolver{P: post}, nil
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// StoryAddArgs is args for the addStory mutation
|
||||
type StoryAddArgs struct {
|
||||
Input *struct {
|
||||
Name string
|
||||
Category string
|
||||
Author *string
|
||||
Open *bool
|
||||
Listed *bool
|
||||
FictionalDate *string
|
||||
Tags *[]struct {
|
||||
Kind string
|
||||
Name string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AddStory resolves the addStory mutation
|
||||
func (r *MutationResolver) AddStory(ctx context.Context, args *StoryAddArgs) (*types.StoryResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member", "story.add") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
author := token.UserID
|
||||
if input.Author != nil {
|
||||
author = *input.Author
|
||||
|
||||
if token.UserID != author && !token.Permitted("story.add") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
}
|
||||
|
||||
listed := (input.Listed != nil && *input.Listed == true)
|
||||
|
||||
open := (input.Open != nil && *input.Open == true)
|
||||
|
||||
tags := make([]story.Tag, 0, 8)
|
||||
if input.Tags != nil {
|
||||
for _, tagInput := range *input.Tags {
|
||||
tags = append(tags, story.Tag{
|
||||
Kind: tagInput.Kind,
|
||||
Name: tagInput.Name,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fictionalDate := time.Time{}
|
||||
if input.FictionalDate != nil {
|
||||
date, err := time.Parse(time.RFC3339Nano, *input.FictionalDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fictionalDate = date
|
||||
}
|
||||
|
||||
story, err := story.New(input.Name, author, input.Category, listed, open, tags, time.Now(), fictionalDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Story", "add", token.UserID, story.ID, map[string]interface{}{
|
||||
"name": input.Name,
|
||||
"category": input.Category,
|
||||
"author": input.Author,
|
||||
})
|
||||
|
||||
return &types.StoryResolver{S: story}, nil
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// StoryTagAddArgs is args for the addStoryTag mutation
|
||||
type StoryTagAddArgs struct {
|
||||
Input *struct {
|
||||
ID string
|
||||
Tag struct {
|
||||
Kind string
|
||||
Name string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AddStoryTag resolves the addStoryTag mutation
|
||||
func (r *MutationResolver) AddStoryTag(ctx context.Context, args *StoryTagAddArgs) (*types.StoryResolver, error) {
|
||||
input := args.Input
|
||||
tag := story.Tag{Kind: input.Tag.Kind, Name: input.Tag.Name}
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member", "story.edit") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
story, err := story.FindID(input.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if story.Author != token.UserID && !token.Permitted("story.edit") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
|
||||
err = story.AddTag(tag)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Story", "add.tag", token.UserID, story.ID, map[string]interface{}{
|
||||
"kind": tag.Kind,
|
||||
"name": tag.Name,
|
||||
})
|
||||
|
||||
return &types.StoryResolver{S: story}, nil
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/channel"
|
||||
)
|
||||
|
||||
// ChannelEditArgs is input for the editChannel mutation
|
||||
type ChannelEditArgs struct {
|
||||
Input *struct {
|
||||
Name string
|
||||
Logged *bool
|
||||
Hub *bool
|
||||
EventName *string
|
||||
LocationName *string
|
||||
}
|
||||
}
|
||||
|
||||
// EditChannel resolves the editChannel mutation
|
||||
func (r *MutationResolver) EditChannel(ctx context.Context, args *ChannelEditArgs) (*types.ChannelResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("channel.edit") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
channel, err := channel.FindName(input.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = channel.Edit(input.Logged, input.Hub, input.EventName, input.LocationName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Channel", "edit", token.UserID, channel.Name, map[string]interface{}{
|
||||
"logged": input.Logged,
|
||||
"hub": input.Hub,
|
||||
"location": input.LocationName,
|
||||
"event": input.EventName,
|
||||
})
|
||||
|
||||
return &types.ChannelResolver{C: channel}, nil
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// EditChapterArgs is args for the editChapter mutation
|
||||
type EditChapterArgs struct {
|
||||
Input *struct {
|
||||
ID string
|
||||
Title *string
|
||||
Source *string
|
||||
FictionalDate *string
|
||||
}
|
||||
}
|
||||
|
||||
// EditChapter resolves the editChapter mutation
|
||||
func (r *MutationResolver) EditChapter(ctx context.Context, args *EditChapterArgs) (*types.ChapterResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member", "chapter.edit") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
chapter, err := story.FindChapterID(input.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if chapter.Author != token.UserID && !token.Permitted("chapter.edit") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
|
||||
var fictionalDate *time.Time
|
||||
if input.FictionalDate != nil {
|
||||
date, err := time.Parse(time.RFC3339Nano, *input.FictionalDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fictionalDate = &date
|
||||
}
|
||||
|
||||
err = chapter.Edit(input.Title, input.Source, fictionalDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Chapter", "edit", token.UserID, chapter.ID, map[string]interface{}{
|
||||
"title": input.Title,
|
||||
"source": input.Source,
|
||||
"fictionalDate": fictionalDate,
|
||||
})
|
||||
|
||||
return &types.ChapterResolver{C: chapter}, nil
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/character"
|
||||
)
|
||||
|
||||
// CharacterEditInput is args for mutation addCharacterNick/removeCharacterNick
|
||||
type CharacterEditInput struct {
|
||||
ID string
|
||||
Name *string
|
||||
ShortName *string
|
||||
Description *string
|
||||
}
|
||||
|
||||
// EditCharacter resolves the editCharacter mutation
|
||||
func (r *MutationResolver) EditCharacter(ctx context.Context, args struct{ Input *CharacterEditInput }) (*types.CharacterResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
character, err := character.FindID(input.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if character.Author != token.UserID && !token.Permitted("character.edit") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
|
||||
name := ""
|
||||
if input.Name != nil {
|
||||
name = *input.Name
|
||||
}
|
||||
|
||||
shortName := ""
|
||||
if input.ShortName != nil {
|
||||
shortName = *input.ShortName
|
||||
}
|
||||
|
||||
description := ""
|
||||
if input.Description != nil {
|
||||
description = *input.Description
|
||||
}
|
||||
|
||||
err = character.Edit(name, shortName, description)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Character", "edit", token.UserID, character.ID, map[string]interface{}{
|
||||
"name": character.Name,
|
||||
"shortName": character.ShortName,
|
||||
"description": character.Description,
|
||||
})
|
||||
|
||||
return &types.CharacterResolver{C: character}, nil
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/file"
|
||||
)
|
||||
|
||||
// FileEditArgs is args for the editFile mutation
|
||||
type FileEditArgs struct {
|
||||
Input *struct {
|
||||
ID string
|
||||
Name *string
|
||||
Public *bool
|
||||
}
|
||||
}
|
||||
|
||||
// EditFile resolves the editFile mutation
|
||||
func (r *MutationResolver) EditFile(ctx context.Context, args *FileEditArgs) (*types.FileResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
file, err := file.FindID(input.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if file.Author != token.UserID && !token.Permitted("file.edit") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
err = file.Edit(input.Name, input.Public)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.FileResolver{F: file}, nil
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// LogEditArgs is args for the editLog mutation
|
||||
type LogEditArgs struct {
|
||||
Input *struct {
|
||||
ID string
|
||||
Title *string
|
||||
Event *string
|
||||
Description *string
|
||||
Open *bool
|
||||
}
|
||||
}
|
||||
|
||||
// EditLog resolves the editLog mutation
|
||||
func (r *MutationResolver) EditLog(ctx context.Context, args *LogEditArgs) (*types.LogResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("log.edit") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
log, err := log.FindID(input.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = log.Edit(input.Title, input.Event, input.Description, input.Open)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Log", "edit", token.UserID, log.ID, map[string]interface{}{
|
||||
"channel": log.Channel,
|
||||
"title": input.Title,
|
||||
"event": input.Event,
|
||||
"description": input.Description,
|
||||
"open": input.Open,
|
||||
})
|
||||
|
||||
return &types.LogResolver{L: log}, nil
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// PostEditArgs is args for the editPost mutation
|
||||
type PostEditArgs struct {
|
||||
Input *struct {
|
||||
ID string
|
||||
Time *string
|
||||
Kind *string
|
||||
Nick *string
|
||||
Text *string
|
||||
}
|
||||
}
|
||||
|
||||
// EditPost resolves the editPost mutation
|
||||
func (r *MutationResolver) EditPost(ctx context.Context, args *PostEditArgs) (*types.PostResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("post.edit") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
postTime := (*time.Time)(nil)
|
||||
if args.Input.Time != nil {
|
||||
t, err := time.Parse(time.RFC3339Nano, *input.Time)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
postTime = &t
|
||||
}
|
||||
|
||||
post, err := log.FindPostID(input.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = post.Edit(postTime, input.Kind, input.Nick, input.Text)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Post", "edit", token.UserID, post.ID, map[string]interface{}{
|
||||
"time": postTime,
|
||||
"kind": input.Kind,
|
||||
"nick": input.Nick,
|
||||
"text": input.Text,
|
||||
})
|
||||
|
||||
go log.UpdateCharacters(post.LogID)
|
||||
|
||||
return &types.PostResolver{P: post}, nil
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// StoryEditArgs is args for the addStory mutation
|
||||
type StoryEditArgs struct {
|
||||
Input *struct {
|
||||
ID string
|
||||
Name *string
|
||||
Category *string
|
||||
Author *string
|
||||
Open *bool
|
||||
Listed *bool
|
||||
FictionalDate *string
|
||||
}
|
||||
}
|
||||
|
||||
// EditStory resolves the editStory mutation
|
||||
func (r *MutationResolver) EditStory(ctx context.Context, args *StoryEditArgs) (*types.StoryResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member", "story.edit") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
story, err := story.FindID(input.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if story.Author != token.UserID && !token.Permitted("story.edit") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
|
||||
var fictionalDate *time.Time
|
||||
if input.FictionalDate != nil {
|
||||
date, err := time.Parse(time.RFC3339Nano, *input.FictionalDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fictionalDate = &date
|
||||
}
|
||||
|
||||
err = story.Edit(input.Name, input.Category, input.Listed, input.Open, fictionalDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Story", "edit", token.UserID, story.ID, map[string]interface{}{
|
||||
"name": input.Name,
|
||||
"category": input.Category,
|
||||
"author": input.Author,
|
||||
"open": input.Open,
|
||||
"listed": input.Listed,
|
||||
"fictionalDate": input.FictionalDate,
|
||||
})
|
||||
|
||||
return &types.StoryResolver{S: story}, nil
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// PostMoveArgs is args for movePost mutation
|
||||
type PostMoveArgs struct {
|
||||
Input *struct {
|
||||
ID string
|
||||
ToPosition int32
|
||||
}
|
||||
}
|
||||
|
||||
// MovePost resolves the movePost mutation
|
||||
func (r *MutationResolver) MovePost(ctx context.Context, args *PostMoveArgs) (*types.PostResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("post.move") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
post, err := log.FindPostID(input.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = post.Move(int(input.ToPosition))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Post", "move", token.UserID, post.ID, map[string]interface{}{
|
||||
"logId": post.LogID,
|
||||
"targetIndex": input.ToPosition,
|
||||
})
|
||||
|
||||
return &types.PostResolver{P: post}, nil
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/channel"
|
||||
)
|
||||
|
||||
// RemoveChannelArgs is args for removeChannels mutation
|
||||
type RemoveChannelArgs struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
// RemoveChannel resolves the editChannel mutation
|
||||
func (r *MutationResolver) RemoveChannel(ctx context.Context, args RemoveChannelArgs) (*types.ChannelResolver, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("channel.remove") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
channel, err := channel.FindName(args.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = channel.Remove()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Channel", "remove", token.UserID, channel.Name, nil)
|
||||
|
||||
return &types.ChannelResolver{C: channel}, nil
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// RemoveChapterArgs is args for the addChapter mutation
|
||||
type RemoveChapterArgs struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// RemoveChapter resolves the removeChapter mutation
|
||||
func (r *MutationResolver) RemoveChapter(ctx context.Context, args *RemoveChapterArgs) (*types.ChapterResolver, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member", "chapter.edit") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
chapter, err := story.FindChapterID(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = chapter.Remove()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Chapter", "remove", token.UserID, chapter.ID, nil)
|
||||
|
||||
return &types.ChapterResolver{C: chapter}, nil
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/character"
|
||||
)
|
||||
|
||||
// RemoveCharacterArgs is args for the removeCharacter mutation
|
||||
type RemoveCharacterArgs struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// RemoveCharacter resolves the removeCharacter mutation
|
||||
func (r *MutationResolver) RemoveCharacter(ctx context.Context, args RemoveCharacterArgs) (*types.CharacterResolver, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
character, err := character.FindID(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if character.Author != token.UserID && !token.Permitted("character.remove") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
|
||||
err = character.Remove()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Character", "remove", token.UserID, character.ID, map[string]interface{}{
|
||||
"name": character.Name,
|
||||
"author": character.Author,
|
||||
"nicks": character.Nicks,
|
||||
})
|
||||
|
||||
return &types.CharacterResolver{C: character}, nil
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/character"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// RemoveCharacterNick is args for the addCharacterNick mutation
|
||||
type RemoveCharacterNick struct {
|
||||
ID string
|
||||
Nick string
|
||||
}
|
||||
|
||||
// RemoveCharacterNick resolves the removeCharacterNick mutation
|
||||
func (r *MutationResolver) RemoveCharacterNick(ctx context.Context, args struct{ Input *RemoveCharacterNick }) (*types.CharacterResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
character, err := character.FindID(input.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if character.Author != token.UserID && !token.Permitted("character.edit") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
|
||||
err = character.RemoveNick(input.Nick)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Character", "remove.nick", token.UserID, character.ID, map[string]interface{}{
|
||||
"nick": input.Nick,
|
||||
})
|
||||
|
||||
log.ScheduleCharacterUpdate()
|
||||
|
||||
return &types.CharacterResolver{C: character}, nil
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/file"
|
||||
)
|
||||
|
||||
// RemoveFileArgs is an arg
|
||||
type RemoveFileArgs struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// RemoveFile resolves the removeFIle mutation
|
||||
func (r *MutationResolver) RemoveFile(ctx context.Context, args *RemoveFileArgs) (*types.FileResolver, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
file, err := file.FindID(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if file.Author != token.UserID && !token.Permitted("file.remove") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
err = file.Delete()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.FileResolver{F: file}, nil
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// RemoveLogArgs is args for the removeLog mutation
|
||||
type RemoveLogArgs struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// RemoveLog resolves the removeLog mutation
|
||||
func (r *MutationResolver) RemoveLog(ctx context.Context, args *RemoveLogArgs) (*types.LogResolver, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("log.remove") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
log, err := log.FindID(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = log.Remove()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Log", "remove", token.UserID, log.ID, nil)
|
||||
|
||||
return &types.LogResolver{L: log}, nil
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// PostRemoveArgs is args for the removePost mutation
|
||||
type PostRemoveArgs struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// RemovePost resolves the removePost mutation
|
||||
func (r *MutationResolver) RemovePost(ctx context.Context, args PostRemoveArgs) (*types.PostResolver, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("post.remove") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
post, err := log.RemovePost(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Post", "remove", token.UserID, post.ID, map[string]interface{}{
|
||||
"logId": post.LogID,
|
||||
})
|
||||
|
||||
go log.UpdateCharacters(post.LogID)
|
||||
|
||||
return &types.PostResolver{P: post}, nil
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// StoryRemoveArgs is args for the removeStory mutation
|
||||
type StoryRemoveArgs struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// RemoveStory resolves the removeStory mutation
|
||||
func (r *MutationResolver) RemoveStory(ctx context.Context, args *StoryRemoveArgs) (*types.StoryResolver, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member", "story.edit") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
story, err := story.FindID(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if story.Author != token.UserID && !token.Permitted("story.remove") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
|
||||
err = story.Remove()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Story", "remove", token.UserID, story.ID, nil)
|
||||
|
||||
return &types.StoryResolver{S: story}, nil
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// StoryTagRemoveArgs is args for the removeStoryTag mutation
|
||||
type StoryTagRemoveArgs struct {
|
||||
Input *struct {
|
||||
ID string
|
||||
Tag struct {
|
||||
Kind string
|
||||
Name string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// RemoveStoryTag resolves the removeStoryTag mutation
|
||||
func (r *MutationResolver) RemoveStoryTag(ctx context.Context, args *StoryTagRemoveArgs) (*types.StoryResolver, error) {
|
||||
input := args.Input
|
||||
tag := story.Tag{Kind: input.Tag.Kind, Name: input.Tag.Name}
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member", "story.edit") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
story, err := story.FindID(input.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if story.Author != token.UserID && !token.Permitted("story.edit") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
|
||||
err = story.RemoveTag(tag)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Story", "remove.tag", token.UserID, story.ID, map[string]interface{}{
|
||||
"kind": tag.Kind,
|
||||
"name": tag.Name,
|
||||
})
|
||||
|
||||
return &types.StoryResolver{S: story}, nil
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
// Package mutations contains resolvers for individual GrahpQL mutations. They were previously mixed in with one another, but that caused
|
||||
// difficulty seeking out specific mutations.
|
||||
package mutations
|
||||
|
||||
import "errors"
|
||||
|
||||
// MutationResolver is a resolver for all mutations. The stuttery name is due to being embedded in the root resolver.
|
||||
type MutationResolver struct{}
|
||||
|
||||
// ErrUnauthorized is when a guest acts like they own the place
|
||||
var ErrUnauthorized = errors.New("Unauthorized")
|
||||
|
||||
// ErrPermissionDenied is returned when users act above their station
|
||||
var ErrPermissionDenied = errors.New("Permission denied")
|
||||
@@ -1,23 +0,0 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/model/channel"
|
||||
)
|
||||
|
||||
// ChannelArgs is args for channel query
|
||||
type ChannelArgs struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
// Channel resolves the channel query
|
||||
func (r *QueryResolver) Channel(ctx context.Context, args *ChannelArgs) (*types.ChannelResolver, error) {
|
||||
channel, err := channel.FindName(args.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.ChannelResolver{C: channel}, nil
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/model/channel"
|
||||
)
|
||||
|
||||
// ChannelsArgs is args for channel query
|
||||
type ChannelsArgs struct {
|
||||
Filter *struct {
|
||||
Logged *bool
|
||||
EventName *string
|
||||
LocationName *string
|
||||
}
|
||||
}
|
||||
|
||||
// Channels resolves the channels query
|
||||
func (r *QueryResolver) Channels(ctx context.Context, args *ChannelsArgs) ([]*types.ChannelResolver, error) {
|
||||
var channels []channel.Channel
|
||||
var err error
|
||||
|
||||
filter := args.Filter
|
||||
if filter != nil {
|
||||
channels, err = channel.List(filter.Logged, filter.EventName, filter.LocationName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
channels, err = channel.List(nil, nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
resolvers := make([]*types.ChannelResolver, len(channels))
|
||||
for i := range channels {
|
||||
resolvers[i] = &types.ChannelResolver{C: channels[i]}
|
||||
}
|
||||
|
||||
return resolvers, nil
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// ChapterArgs is args for chapter query
|
||||
type ChapterArgs struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// Chapter resolves the chapter query
|
||||
func (r *QueryResolver) Chapter(ctx context.Context, args *ChapterArgs) (*types.ChapterResolver, error) {
|
||||
chapter, err := story.FindChapterID(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.ChapterResolver{C: chapter}, nil
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/model/character"
|
||||
)
|
||||
|
||||
// ErrIncorrectArguments is returned by character query.
|
||||
var ErrIncorrectArguments = errors.New("You can only query character by ID or Nick")
|
||||
|
||||
// CharacterArgs is args for character query
|
||||
type CharacterArgs struct {
|
||||
ID *string
|
||||
Nick *string
|
||||
}
|
||||
|
||||
// Character resolves the character query
|
||||
func (r *QueryResolver) Character(ctx context.Context, args *CharacterArgs) (*types.CharacterResolver, error) {
|
||||
var char character.Character
|
||||
var err error
|
||||
|
||||
if args.Nick != nil && args.ID != nil {
|
||||
return nil, ErrIncorrectArguments
|
||||
}
|
||||
|
||||
switch {
|
||||
case args.ID != nil:
|
||||
char, err = character.FindID(*args.ID)
|
||||
case args.Nick != nil:
|
||||
char, err = character.FindNick(*args.Nick)
|
||||
default:
|
||||
err = ErrIncorrectArguments
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.CharacterResolver{C: char}, nil
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/model/character"
|
||||
)
|
||||
|
||||
// CharactersArgs is args for characters query
|
||||
type CharactersArgs struct {
|
||||
Filter *struct {
|
||||
IDs *[]string
|
||||
Nicks *[]string
|
||||
Names *[]string
|
||||
Author *string
|
||||
Search *string
|
||||
Logged *bool
|
||||
}
|
||||
}
|
||||
|
||||
// Characters resolves the characters query
|
||||
func (r *QueryResolver) Characters(ctx context.Context, args *CharactersArgs) ([]*types.CharacterResolver, error) {
|
||||
var characters []character.Character
|
||||
var err error
|
||||
|
||||
filter := args.Filter
|
||||
if filter != nil {
|
||||
var ids []string
|
||||
var nicks []string
|
||||
var names []string
|
||||
|
||||
if filter.IDs != nil {
|
||||
ids = *filter.IDs
|
||||
}
|
||||
if filter.Nicks != nil {
|
||||
nicks = *filter.Nicks
|
||||
}
|
||||
if filter.Names != nil {
|
||||
names = *filter.Names
|
||||
}
|
||||
|
||||
characters, err = character.ListFilter(ids, nicks, names, filter.Author, filter.Search, filter.Logged)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
characters, err = character.List()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
resolvers := make([]*types.CharacterResolver, 0, len(characters))
|
||||
for _, character := range characters {
|
||||
resolvers = append(resolvers, &types.CharacterResolver{C: character})
|
||||
}
|
||||
|
||||
return resolvers, nil
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/model/file"
|
||||
)
|
||||
|
||||
// FileArgs is args for file query
|
||||
type FileArgs struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// File resolves the file query
|
||||
func (r *QueryResolver) File(ctx context.Context, args *FileArgs) (*types.FileResolver, error) {
|
||||
file, err := file.FindID(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.FileResolver{F: file}, nil
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/file"
|
||||
)
|
||||
|
||||
// FilesArgs is args for files query
|
||||
type FilesArgs struct {
|
||||
Filter *struct {
|
||||
Public *bool
|
||||
MimeTypes *[]string
|
||||
}
|
||||
}
|
||||
|
||||
// Files resolves the file query
|
||||
func (r *QueryResolver) Files(ctx context.Context, args *FilesArgs) ([]*types.FileResolver, error) {
|
||||
filter := args.Filter
|
||||
token := auth.TokenFromContext(ctx)
|
||||
|
||||
author := ""
|
||||
if token != nil {
|
||||
author = token.UserID
|
||||
}
|
||||
|
||||
mimeTypes := []string(nil)
|
||||
if filter.MimeTypes != nil {
|
||||
mimeTypes = *filter.MimeTypes
|
||||
}
|
||||
|
||||
files, err := file.List(author, filter.Public, mimeTypes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resolvers := make([]*types.FileResolver, len(files))
|
||||
for i := range files {
|
||||
resolvers[i] = &types.FileResolver{F: files[i]}
|
||||
}
|
||||
|
||||
return resolvers, nil
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// LogArgs is args for log query
|
||||
type LogArgs struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// Log resolves the log query
|
||||
func (r *QueryResolver) Log(ctx context.Context, args *LogArgs) (*types.LogResolver, error) {
|
||||
log, err := log.FindID(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.LogResolver{L: log}, nil
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/loader"
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// LogsArgs is args for the logs query
|
||||
type LogsArgs struct {
|
||||
Filter *log.Filter
|
||||
}
|
||||
|
||||
// Logs resolves the logs query
|
||||
func (r *QueryResolver) Logs(ctx context.Context, args *LogsArgs) ([]*types.LogResolver, error) {
|
||||
var logs []log.Log
|
||||
|
||||
filter := args.Filter
|
||||
if filter == nil {
|
||||
filter = log.NewFilter().WithLimit(100)
|
||||
}
|
||||
|
||||
logs, err := log.List(filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(logs) >= 100 {
|
||||
loader := loader.FromContext(ctx)
|
||||
if loader == nil {
|
||||
return nil, errors.New("no loader")
|
||||
}
|
||||
|
||||
for _, log := range logs {
|
||||
loader.PrimeCharacters("id", log.CharacterIDs...)
|
||||
loader.PrimeChannels("name", log.Channel)
|
||||
}
|
||||
}
|
||||
|
||||
resolvers := make([]*types.LogResolver, len(logs))
|
||||
for i := range logs {
|
||||
resolvers[i] = &types.LogResolver{L: logs[i]}
|
||||
}
|
||||
|
||||
return resolvers, nil
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// PostArgs is args for the post query
|
||||
type PostArgs struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// Post resolves the post query
|
||||
func (r *QueryResolver) Post(ctx context.Context, args *PostArgs) (*types.PostResolver, error) {
|
||||
post, err := log.FindPostID(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.PostResolver{P: post}, nil
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// PostsArgs is args for the posts query
|
||||
type PostsArgs struct {
|
||||
IDs []string
|
||||
}
|
||||
|
||||
// Posts resolves the posts query
|
||||
func (r *QueryResolver) Posts(ctx context.Context, args *PostsArgs) ([]*types.PostResolver, error) {
|
||||
posts, err := log.ListPostIDs(args.IDs...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resolvers := make([]*types.PostResolver, len(posts))
|
||||
for i := range resolvers {
|
||||
resolvers[i] = &types.PostResolver{P: posts[i]}
|
||||
}
|
||||
|
||||
return resolvers, nil
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
// Package queries contains resolvers for individual GrahpQL queries. They were previously mixed in with one another, but that caused
|
||||
// difficulty seeking out specific queries.
|
||||
package queries
|
||||
|
||||
import "errors"
|
||||
|
||||
// QueryResolver is a resolver for all queries. The stuttery name is due to being embedded in the root resolver.
|
||||
type QueryResolver struct{}
|
||||
|
||||
// ErrCannotResolve is returned when a resolver constructor is at its wit's end
|
||||
var ErrCannotResolve = errors.New("Cannot resolve due to invalid arguments")
|
||||
|
||||
// ErrUnauthorized is when a guest acts like they own the place
|
||||
var ErrUnauthorized = errors.New("Unauthorized")
|
||||
|
||||
// ErrPermissionDenied is returned when users act above their station
|
||||
var ErrPermissionDenied = errors.New("Permission denied")
|
||||
@@ -1,109 +0,0 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// StoriesArg is args for stories query
|
||||
type StoriesArg struct {
|
||||
Filter *struct {
|
||||
Author *string
|
||||
Tags *[]struct {
|
||||
Kind string
|
||||
Name string
|
||||
}
|
||||
EarliestFictionalDate *string
|
||||
LatestFictionalDate *string
|
||||
Category *string
|
||||
Limit *int32
|
||||
Open *bool
|
||||
Unlisted *bool
|
||||
}
|
||||
}
|
||||
|
||||
// Stories resolves the stories query
|
||||
func (r *QueryResolver) Stories(ctx context.Context, args *StoriesArg) ([]*types.StoryResolver, error) {
|
||||
var err error
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
|
||||
filter := args.Filter
|
||||
|
||||
author := ""
|
||||
category := ""
|
||||
tags := make([]story.Tag, 0, 8)
|
||||
earliest := time.Time{}
|
||||
latest := time.Time{}
|
||||
unlisted := false
|
||||
open := (*bool)(nil)
|
||||
limit := 0
|
||||
|
||||
if filter != nil {
|
||||
if filter.Author != nil {
|
||||
author = *filter.Author
|
||||
}
|
||||
|
||||
if filter.Category != nil {
|
||||
category = *filter.Category
|
||||
}
|
||||
|
||||
if filter.Tags != nil {
|
||||
for _, tagInput := range *filter.Tags {
|
||||
tags = append(tags, story.Tag{
|
||||
Kind: tagInput.Kind,
|
||||
Name: tagInput.Name,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if filter.EarliestFictionalDate != nil {
|
||||
earliest, err = time.Parse(time.RFC3339Nano, *filter.EarliestFictionalDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if filter.LatestFictionalDate != nil {
|
||||
latest, err = time.Parse(time.RFC3339Nano, *filter.LatestFictionalDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if filter.Limit != nil {
|
||||
limit = int(*filter.Limit)
|
||||
}
|
||||
|
||||
unlisted = filter.Unlisted != nil && *filter.Unlisted == true
|
||||
if unlisted {
|
||||
if token == nil {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
if author != "" && author != token.UserID && !token.Permitted("story.unlisted") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
|
||||
author = token.UserID
|
||||
}
|
||||
|
||||
open = filter.Open
|
||||
}
|
||||
|
||||
stories, err := story.List(author, category, tags, earliest, latest, unlisted, open, limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resolvers := make([]*types.StoryResolver, len(stories))
|
||||
for i, story := range stories {
|
||||
resolvers[i] = &types.StoryResolver{S: story}
|
||||
}
|
||||
|
||||
return resolvers, nil
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// StoryArgs is args for story query
|
||||
type StoryArgs struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// Story resolves the story query
|
||||
func (r *QueryResolver) Story(ctx context.Context, args *StoryArgs) (*types.StoryResolver, error) {
|
||||
story, err := story.FindID(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.StoryResolver{S: story}, nil
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// Tags resolves the tags query
|
||||
func (r *QueryResolver) Tags() ([]*types.TagResolver, error) {
|
||||
tags, err := story.ListTags()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resolvers := make([]*types.TagResolver, len(tags))
|
||||
for i, tag := range tags {
|
||||
resolvers[i] = &types.TagResolver{T: tag}
|
||||
}
|
||||
|
||||
return resolvers, nil
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package resolver
|
||||
|
||||
import (
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/mutations"
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/queries"
|
||||
)
|
||||
|
||||
// The Resolver combines the query and mutation resolvers from the subpackages.
|
||||
// This is the one to pass along with the schema.
|
||||
type Resolver struct {
|
||||
queries.QueryResolver
|
||||
mutations.MutationResolver
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package types
|
||||
|
||||
import "git.aiterp.net/rpdata/api/model/channel"
|
||||
|
||||
// ChannelResolver for the Channel graphql type
|
||||
type ChannelResolver struct{ C channel.Channel }
|
||||
|
||||
// Name resolves channel.name
|
||||
func (r *ChannelResolver) Name() string {
|
||||
return r.C.Name
|
||||
}
|
||||
|
||||
// Logged resolves channel.logged
|
||||
func (r *ChannelResolver) Logged() bool {
|
||||
return r.C.Logged
|
||||
}
|
||||
|
||||
// Hub resolves channel.hub
|
||||
func (r *ChannelResolver) Hub() bool {
|
||||
return r.C.Hub
|
||||
}
|
||||
|
||||
// EventName resolves channel.eventName
|
||||
func (r *ChannelResolver) EventName() *string {
|
||||
if r.C.Event == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &r.C.Event
|
||||
}
|
||||
|
||||
// LocationName resolves channel.locationName
|
||||
func (r *ChannelResolver) LocationName() *string {
|
||||
if r.C.Location == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &r.C.Location
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// ChapterResolver for the Chapter graphql type
|
||||
type ChapterResolver struct{ C story.Chapter }
|
||||
|
||||
// ID resolves Chapter.id
|
||||
func (r *ChapterResolver) ID() string {
|
||||
return r.C.ID
|
||||
}
|
||||
|
||||
// StoryID resolves Chapter.storyId
|
||||
func (r *ChapterResolver) StoryID() string {
|
||||
return r.C.StoryID
|
||||
}
|
||||
|
||||
// Title resolves Chapter.title
|
||||
func (r *ChapterResolver) Title() string {
|
||||
return r.C.Title
|
||||
}
|
||||
|
||||
// Author resolves Chapter.author
|
||||
func (r *ChapterResolver) Author() string {
|
||||
return r.C.Author
|
||||
}
|
||||
|
||||
// Source resolves Chapter.source
|
||||
func (r *ChapterResolver) Source() string {
|
||||
return r.C.Source
|
||||
}
|
||||
|
||||
// CreatedDate resolves Chapter.createdDate
|
||||
func (r *ChapterResolver) CreatedDate() string {
|
||||
return r.C.CreatedDate.Format(time.RFC3339Nano)
|
||||
}
|
||||
|
||||
// FictionalDate resolves Chapter.fictionalDate
|
||||
func (r *ChapterResolver) FictionalDate() string {
|
||||
return r.C.FictionalDate.Format(time.RFC3339Nano)
|
||||
}
|
||||
|
||||
// EditedDate resolves Chapter.editedDate
|
||||
func (r *ChapterResolver) EditedDate() string {
|
||||
return r.C.EditedDate.Format(time.RFC3339Nano)
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package types
|
||||
|
||||
import "git.aiterp.net/rpdata/api/model/character"
|
||||
|
||||
// CharacterResolver for the Character graphql type
|
||||
type CharacterResolver struct{ C character.Character }
|
||||
|
||||
// ID is a property resolver
|
||||
func (r *CharacterResolver) ID() string {
|
||||
return r.C.ID
|
||||
}
|
||||
|
||||
// Nick is a property resolver
|
||||
func (r *CharacterResolver) Nick() *string {
|
||||
if len(r.C.Nicks) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &r.C.Nicks[0]
|
||||
}
|
||||
|
||||
// Nicks is a property resolver
|
||||
func (r *CharacterResolver) Nicks() []string {
|
||||
return r.C.Nicks
|
||||
}
|
||||
|
||||
// Name is a property resolver
|
||||
func (r *CharacterResolver) Name() string {
|
||||
return r.C.Name
|
||||
}
|
||||
|
||||
// ShortName is a property resolver
|
||||
func (r *CharacterResolver) ShortName() string {
|
||||
return r.C.ShortName
|
||||
}
|
||||
|
||||
// Author is a property resolver
|
||||
func (r *CharacterResolver) Author() string {
|
||||
return r.C.Author
|
||||
}
|
||||
|
||||
// Description is a property resolver
|
||||
func (r *CharacterResolver) Description() string {
|
||||
return r.C.Description
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/model/file"
|
||||
)
|
||||
|
||||
// FileResolver for the File graphql type
|
||||
type FileResolver struct{ F file.File }
|
||||
|
||||
// ID resolves File.id
|
||||
func (f *FileResolver) ID() string {
|
||||
return f.F.ID
|
||||
}
|
||||
|
||||
// Author resolves File.author
|
||||
func (f *FileResolver) Author() string {
|
||||
return f.F.Author
|
||||
}
|
||||
|
||||
// Kind resolves File.kind
|
||||
func (f *FileResolver) Kind() string {
|
||||
return f.F.Kind
|
||||
}
|
||||
|
||||
// Time resolves File.time
|
||||
func (f *FileResolver) Time() string {
|
||||
return f.F.Time.Format(time.RFC3339Nano)
|
||||
}
|
||||
|
||||
// Public resolves File.public
|
||||
func (f *FileResolver) Public() bool {
|
||||
return f.F.Public
|
||||
}
|
||||
|
||||
// Name resolves File.name
|
||||
func (f *FileResolver) Name() string {
|
||||
return f.F.Name
|
||||
}
|
||||
|
||||
// MimeType resolves File.mimeType
|
||||
func (f *FileResolver) MimeType() string {
|
||||
return f.F.MimeType
|
||||
}
|
||||
|
||||
// Size resolves File.size
|
||||
func (f *FileResolver) Size() int32 {
|
||||
return int32(f.F.Size)
|
||||
}
|
||||
|
||||
// URL resolves File.url
|
||||
func (f *FileResolver) URL() *string {
|
||||
if f.F.URL == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &f.F.URL
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/loader"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// LogResolver for the Log graphql type
|
||||
type LogResolver struct{ L log.Log }
|
||||
|
||||
// ID resolves Log.id
|
||||
func (r *LogResolver) ID() string {
|
||||
return r.L.ID
|
||||
}
|
||||
|
||||
// ShortID resolves Log.shortId
|
||||
func (r *LogResolver) ShortID() string {
|
||||
return r.L.ShortID
|
||||
}
|
||||
|
||||
// Date resolves Log.date
|
||||
func (r *LogResolver) Date() string {
|
||||
return r.L.Date.Format(time.RFC3339Nano)
|
||||
}
|
||||
|
||||
// ChannelName resolves Log.channelName
|
||||
func (r *LogResolver) ChannelName() string {
|
||||
return r.L.Channel
|
||||
}
|
||||
|
||||
// Channel resolves Log.channe
|
||||
func (r *LogResolver) Channel(ctx context.Context) (*ChannelResolver, error) {
|
||||
loader := loader.FromContext(ctx)
|
||||
if loader == nil {
|
||||
return nil, errors.New("no loader")
|
||||
}
|
||||
|
||||
channel, err := loader.Channel("name", r.L.Channel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ChannelResolver{C: channel}, nil
|
||||
}
|
||||
|
||||
// Title resolves Log.title
|
||||
func (r *LogResolver) Title() string {
|
||||
return r.L.Title
|
||||
}
|
||||
|
||||
// Event resolves Log.event
|
||||
func (r *LogResolver) Event() string {
|
||||
return r.L.Event
|
||||
}
|
||||
|
||||
// Description resolves Log.description
|
||||
func (r *LogResolver) Description() string {
|
||||
return r.L.Description
|
||||
}
|
||||
|
||||
// Open resolves Log.open
|
||||
func (r *LogResolver) Open() bool {
|
||||
return r.L.Open
|
||||
}
|
||||
|
||||
// Characters resolves Log.characters
|
||||
func (r *LogResolver) Characters(ctx context.Context) ([]*CharacterResolver, error) {
|
||||
loader := loader.FromContext(ctx)
|
||||
if loader == nil {
|
||||
return nil, errors.New("no loader")
|
||||
}
|
||||
|
||||
chars, err := loader.Characters("id", r.L.CharacterIDs...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resolvers := make([]*CharacterResolver, 0, len(chars))
|
||||
for i := range chars {
|
||||
if chars[i].ID == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
resolvers = append(resolvers, &CharacterResolver{C: chars[i]})
|
||||
}
|
||||
|
||||
return resolvers, nil
|
||||
}
|
||||
|
||||
// Posts resolves Log.posts
|
||||
func (r *LogResolver) Posts(ctx context.Context, args *LogPostArgs) ([]*PostResolver, error) {
|
||||
var kinds []string
|
||||
if args.Kinds != nil {
|
||||
kinds = *args.Kinds
|
||||
}
|
||||
|
||||
posts, err := r.L.Posts(kinds...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resolvers := make([]*PostResolver, len(posts))
|
||||
for i := range posts {
|
||||
resolvers[i] = &PostResolver{posts[i]}
|
||||
}
|
||||
|
||||
return resolvers, nil
|
||||
}
|
||||
|
||||
// LogPostArgs is an arg
|
||||
type LogPostArgs struct {
|
||||
Kinds *[]string
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// PostResolver for the Post graphql type
|
||||
type PostResolver struct{ P log.Post }
|
||||
|
||||
// ID resolves Post.id
|
||||
func (r *PostResolver) ID() string {
|
||||
return r.P.ID
|
||||
}
|
||||
|
||||
// LogID resolves Post.logId
|
||||
func (r *PostResolver) LogID() string {
|
||||
return r.P.LogID
|
||||
}
|
||||
|
||||
// Time resolves Post.time
|
||||
func (r *PostResolver) Time() string {
|
||||
return r.P.Time.Format(time.RFC3339Nano)
|
||||
}
|
||||
|
||||
// Kind resolves Post.logId
|
||||
func (r *PostResolver) Kind() string {
|
||||
return r.P.Kind
|
||||
}
|
||||
|
||||
// Nick resolves Post.nick
|
||||
func (r *PostResolver) Nick() string {
|
||||
return r.P.Nick
|
||||
}
|
||||
|
||||
// Text resolves Post.text
|
||||
func (r *PostResolver) Text() string {
|
||||
return r.P.Text
|
||||
}
|
||||
|
||||
// Position resolves Post.text
|
||||
func (r *PostResolver) Position() int32 {
|
||||
return int32(r.P.Position)
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// StoryResolver for the Story graphql type
|
||||
type StoryResolver struct{ S story.Story }
|
||||
|
||||
// ID resolves Story.id
|
||||
func (r *StoryResolver) ID() string {
|
||||
return r.S.ID
|
||||
}
|
||||
|
||||
// Author resolves Story.author
|
||||
func (r *StoryResolver) Author() string {
|
||||
return r.S.Author
|
||||
}
|
||||
|
||||
// Name resolves Story.name
|
||||
func (r *StoryResolver) Name() string {
|
||||
return r.S.Name
|
||||
}
|
||||
|
||||
// Category resolves Story.category
|
||||
func (r *StoryResolver) Category() string {
|
||||
return r.S.Category
|
||||
}
|
||||
|
||||
// Open resolves Story.open
|
||||
func (r *StoryResolver) Open() bool {
|
||||
return r.S.Open
|
||||
}
|
||||
|
||||
// Listed resolves Story.listed
|
||||
func (r *StoryResolver) Listed() bool {
|
||||
return r.S.Listed
|
||||
}
|
||||
|
||||
// Tags resolves Story.tags
|
||||
func (r *StoryResolver) Tags() []*TagResolver {
|
||||
resolvers := make([]*TagResolver, len(r.S.Tags))
|
||||
for i, tag := range r.S.Tags {
|
||||
resolvers[i] = &TagResolver{T: tag}
|
||||
}
|
||||
|
||||
return resolvers
|
||||
}
|
||||
|
||||
// Chapters resolves Story.chapters
|
||||
func (r *StoryResolver) Chapters() ([]*ChapterResolver, error) {
|
||||
chapters, err := r.S.Chapters()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resolvers := make([]*ChapterResolver, len(chapters))
|
||||
for i, chapter := range chapters {
|
||||
resolvers[i] = &ChapterResolver{C: chapter}
|
||||
}
|
||||
|
||||
return resolvers, nil
|
||||
}
|
||||
|
||||
// CreatedDate resolves Story.createdDate
|
||||
func (r *StoryResolver) CreatedDate() string {
|
||||
return r.S.CreatedDate.Format(time.RFC3339Nano)
|
||||
}
|
||||
|
||||
// FictionalDate resolves Story.fictionalDate
|
||||
func (r *StoryResolver) FictionalDate() string {
|
||||
return r.S.FictionalDate.Format(time.RFC3339Nano)
|
||||
}
|
||||
|
||||
// UpdatedDate resolves Story.updatedDate
|
||||
func (r *StoryResolver) UpdatedDate() string {
|
||||
return r.S.UpdatedDate.Format(time.RFC3339Nano)
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package types
|
||||
|
||||
import "git.aiterp.net/rpdata/api/model/story"
|
||||
|
||||
// TagResolver for the Tag graphql type
|
||||
type TagResolver struct{ T story.Tag }
|
||||
|
||||
// Kind resolves Tag.kind
|
||||
func (r *TagResolver) Kind() string {
|
||||
return r.T.Kind
|
||||
}
|
||||
|
||||
// Name resolves Tag.name
|
||||
func (r *TagResolver) Name() string {
|
||||
return r.T.Name
|
||||
}
|
||||
@@ -1,141 +0,0 @@
|
||||
# The Query type represents the read entry points into the API.
|
||||
type Query {
|
||||
# Find character by either an ID or a nick.
|
||||
character(id: String, nick: String): Character
|
||||
|
||||
# Find characters
|
||||
characters(filter: CharactersFilter): [Character!]!
|
||||
|
||||
|
||||
# Find channel by name
|
||||
channel(name: String!): Channel
|
||||
|
||||
# Find channels
|
||||
channels(filter: ChannelsFilter): [Channel!]!
|
||||
|
||||
|
||||
# Find log by ID
|
||||
log(id: String!): Log
|
||||
|
||||
# Find logs
|
||||
logs(filter: LogsFilter): [LogHeader!]!
|
||||
|
||||
|
||||
# Find post by ID.
|
||||
post(id: String!): Post
|
||||
|
||||
# Find posts by IDs. It's meant to allow other parts of the UI to link to a cluster of posts, e.g. for a room description for the
|
||||
# Mapp should it ever become a thing. This does not have a filter, since it's meant to be queried in the logs' response's selection set.
|
||||
posts(ids: [String!]!): [Post!]!
|
||||
|
||||
|
||||
# Find file by ID
|
||||
file(id: String!): File
|
||||
|
||||
# Find files
|
||||
files(filter: FilesFilter): [File!]!
|
||||
|
||||
|
||||
# Find story by ID
|
||||
story(id: String!): Story
|
||||
|
||||
# Find stories
|
||||
stories(filter: StoriesFilter): [Story!]!
|
||||
|
||||
|
||||
# Find story chapter by ID
|
||||
chapter(id: String!): Chapter
|
||||
|
||||
|
||||
# Find all distinct tags used in stories
|
||||
tags: [Tag!]!
|
||||
}
|
||||
|
||||
# The Mutation type represents write entry points into the API.
|
||||
type Mutation {
|
||||
# Add a new character
|
||||
addCharacter(input: CharacterAddInput!): Character!
|
||||
|
||||
# Add nick to character
|
||||
addCharacterNick(input: CharacterNickInput!): Character!
|
||||
|
||||
# Remove nick from character
|
||||
removeCharacterNick(input: CharacterNickInput!): Character!
|
||||
|
||||
# Edit character
|
||||
editCharacter(input: CharacterEditInput!): Character!
|
||||
|
||||
# Remove a character
|
||||
removeCharacter(id: String!): Character!
|
||||
|
||||
|
||||
# Add a channel
|
||||
addChannel(input: ChannelAddInput!): Channel!
|
||||
|
||||
# Edit a channel
|
||||
editChannel(input: ChannelEditInput!): Channel!
|
||||
|
||||
# Remove a channel
|
||||
removeChannel(name: String!): Channel!
|
||||
|
||||
|
||||
# Add a new log
|
||||
addLog(input: LogAddInput!): Log!
|
||||
|
||||
# Edit a log
|
||||
editLog(input: LogEditInput!): Log!
|
||||
|
||||
# Remove a log
|
||||
removeLog(id: String!): Log!
|
||||
|
||||
|
||||
# Add a post
|
||||
addPost(input: AddPostInput!): Post!
|
||||
|
||||
# Edit a post
|
||||
editPost(input: EditPostInput!): Post!
|
||||
|
||||
# Move a post
|
||||
movePost(input: MovePostInput!): Post!
|
||||
|
||||
# Remove a post
|
||||
removePost(id: String!): Post!
|
||||
|
||||
|
||||
# Edit a file
|
||||
editFile(input: EditFileInput!): File!
|
||||
|
||||
# Remove a file
|
||||
removeFile(id: String!): File!
|
||||
|
||||
|
||||
# Add a story
|
||||
addStory(input: StoryAddInput!): Story!
|
||||
|
||||
# Add a story tag
|
||||
addStoryTag(input: StoryTagAddInput!): Story!
|
||||
|
||||
# Remove a story tag
|
||||
removeStoryTag(input: StoryTagRemoveInput!): Story!
|
||||
|
||||
# Edit a story
|
||||
editStory(input: StoryEditInput!): Story!
|
||||
|
||||
# Remove a story
|
||||
removeStory(id: String!): Story!
|
||||
|
||||
|
||||
# Add a chapter to a story
|
||||
addChapter(input: ChapterAddInput!): Chapter!
|
||||
|
||||
# Edit a chapter
|
||||
editChapter(input: ChapterEditInput!): Chapter!
|
||||
|
||||
# Remove a chapter
|
||||
removeChapter(id: String!): Chapter!
|
||||
}
|
||||
|
||||
schema {
|
||||
query: Query
|
||||
mutation: Mutation
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package schema
|
||||
|
||||
//go:generate go-bindata -ignore=\.go -pkg=schema -o=bindata.go ./...
|
||||
|
||||
import "bytes"
|
||||
|
||||
// String gets the schema
|
||||
func String() string {
|
||||
buf := bytes.Buffer{}
|
||||
for _, name := range AssetNames() {
|
||||
b := MustAsset(name)
|
||||
buf.Write(b)
|
||||
|
||||
// Add a newline if the file does not end in a newline.
|
||||
if len(b) > 0 && b[len(b)-1] != '\n' {
|
||||
buf.WriteByte('\n')
|
||||
}
|
||||
}
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
# A Change is a part of the history that can be used to keep clients up to date.
|
||||
type Change {
|
||||
id: Int!
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
# Information about an IRC channel
|
||||
type Channel {
|
||||
# The channel's name
|
||||
name: String!
|
||||
|
||||
# Whether the channel should be logged
|
||||
logged: Boolean!
|
||||
|
||||
# Whether the channel is a hub channel
|
||||
hub: Boolean!
|
||||
|
||||
# The event name, or `null` if none is specified
|
||||
eventName: String
|
||||
|
||||
# The location name, or `null` if none is specified
|
||||
locationName: String
|
||||
}
|
||||
|
||||
# Filters for the channels query
|
||||
input ChannelsFilter {
|
||||
# Filter to either logged or unlogged channels
|
||||
logged: Boolean
|
||||
|
||||
# Filter by event name
|
||||
eventName: String
|
||||
|
||||
# Filter by location name
|
||||
locationName: String
|
||||
}
|
||||
|
||||
input ChannelAddInput {
|
||||
# The channel's name
|
||||
name: String!
|
||||
|
||||
# Whether the channel should be logged
|
||||
logged: Boolean
|
||||
|
||||
# Whether the channel is a hub channel
|
||||
hub: Boolean
|
||||
|
||||
# The event name, or `null` if none is specified
|
||||
eventName: String
|
||||
|
||||
# The location name, or `null` if none is specified
|
||||
locationName: String
|
||||
}
|
||||
|
||||
input ChannelEditInput {
|
||||
# The channel's name
|
||||
name: String!
|
||||
|
||||
# Whether the channel should be logged
|
||||
logged: Boolean
|
||||
|
||||
# Whether the channel is a hub channel
|
||||
hub: Boolean
|
||||
|
||||
# The event name, or `null` if none is specified
|
||||
eventName: String
|
||||
|
||||
# The location name, or `null` if none is specified
|
||||
locationName: String
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
# A Chapter is the main content body of a story.
|
||||
type Chapter {
|
||||
# The chapter's ID
|
||||
id: String!
|
||||
|
||||
# The chapter's title
|
||||
title: String!
|
||||
|
||||
# The chapter's author
|
||||
author: String!
|
||||
|
||||
# The chapter's source
|
||||
source: String!
|
||||
|
||||
# When the chapter was posted initialy
|
||||
createdDate: String!
|
||||
|
||||
# The in-universe date and time of the chapter
|
||||
fictionalDate: String!
|
||||
|
||||
# The date of edit.
|
||||
editedDate: String!
|
||||
}
|
||||
|
||||
# Input for addChapter mutation
|
||||
input ChapterAddInput {
|
||||
# The story to add a chapter to
|
||||
storyId: String!
|
||||
|
||||
# The title to give the chapter. It can not be left empty
|
||||
title: String!
|
||||
|
||||
# The author to set for the chapter. It will use the logged in user ID, and only
|
||||
# users with appropriate permissions can post as another author. Even then, it's only
|
||||
# for importing/moving content. This author name will not be used when logging the
|
||||
# submission
|
||||
author: String
|
||||
|
||||
# The markdown source for the content
|
||||
source: String!
|
||||
|
||||
# Optionally, assign a fictional date for the chapter
|
||||
fictionalDate: String
|
||||
}
|
||||
|
||||
# Input for editChapter mutation
|
||||
input ChapterEditInput {
|
||||
# The chapter to edit
|
||||
id: String!
|
||||
|
||||
# Change the chapter's title
|
||||
title: String
|
||||
|
||||
# Change the source
|
||||
source: String
|
||||
|
||||
# Set the fictional date for a chapter
|
||||
fictionalDate: String
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
# A Character represents an RP character
|
||||
type Character {
|
||||
# A unique identifier for the character
|
||||
id: String!
|
||||
|
||||
# The primary IRC nick belonging to the character
|
||||
nick: String
|
||||
|
||||
# All IRC nicks associated with this character
|
||||
nicks: [String!]!
|
||||
|
||||
# The character's author
|
||||
author: String!
|
||||
|
||||
# The character's name
|
||||
name: String!
|
||||
|
||||
# The name to display when space is scarce, usually the first/given name
|
||||
shortName: String!
|
||||
|
||||
# A short description of the character
|
||||
description: String!
|
||||
}
|
||||
|
||||
# Filter for characters query
|
||||
input CharactersFilter {
|
||||
# Filter by character IDs
|
||||
ids: [String!]
|
||||
|
||||
# Filter by nicks
|
||||
nicks: [String!]
|
||||
|
||||
# Filter by names
|
||||
names: [String!]
|
||||
|
||||
# Filter by author
|
||||
author: String
|
||||
|
||||
# Filter by text search matching against the character's description
|
||||
search: String
|
||||
|
||||
# Filter by whether they've been part of a log.
|
||||
logged: Boolean
|
||||
}
|
||||
|
||||
# Input for adding characters
|
||||
input CharacterAddInput {
|
||||
# The primary IRC nick name to recognize this character by
|
||||
nick: String!
|
||||
|
||||
# The character's name
|
||||
name: String!
|
||||
|
||||
# Optioanl shortened name. By default, it uses the first token in the name
|
||||
shortName: String
|
||||
|
||||
# Description for a character.
|
||||
description: String
|
||||
|
||||
# Optioanlly, specify another author. This needs special permissions if it's not
|
||||
# your own username
|
||||
author: String
|
||||
}
|
||||
|
||||
# Input for addNick and removeNick mutation
|
||||
input CharacterNickInput {
|
||||
# The ID of the character
|
||||
id: String!
|
||||
|
||||
# The nick to add or remove
|
||||
nick: String!
|
||||
}
|
||||
|
||||
input CharacterEditInput {
|
||||
# The id for the character to edit
|
||||
id: String!
|
||||
|
||||
# The full name of the character -- not the salarian full name!
|
||||
name: String
|
||||
|
||||
# The character's short name that is used in compact lists
|
||||
shortName: String
|
||||
|
||||
# A short description for the character
|
||||
description: String
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
# A File contains information about a file and where to download it.
|
||||
type File {
|
||||
# The file's unique ID
|
||||
id: String!
|
||||
|
||||
# The kind of file. Most will be "upload", but some that are ported from the wiki will have other values for this.
|
||||
kind: String!
|
||||
|
||||
# The time of uploading
|
||||
time: String!
|
||||
|
||||
# Whether the file is publicly listable. Someone with knowledge of the ID
|
||||
# will still be able to view it, however.
|
||||
public: Boolean!
|
||||
|
||||
# The file's name
|
||||
name: String!
|
||||
|
||||
# The MIME type of the file
|
||||
mimeType: String!
|
||||
|
||||
# The file's size in bytes
|
||||
size: Int!
|
||||
|
||||
# The uploader
|
||||
author: String!
|
||||
|
||||
# The URL where the file is hosted
|
||||
url: String
|
||||
}
|
||||
|
||||
# Filter for the files quiery.
|
||||
input FilesFilter {
|
||||
# If set, this will limit the results to either public or private files.
|
||||
public: Boolean
|
||||
|
||||
# Limit the MIME types of the files.
|
||||
mimeTypes: [String!]
|
||||
}
|
||||
|
||||
# Input for editFile mutation
|
||||
input EditFileInput {
|
||||
# The file's unique ID
|
||||
id: String!
|
||||
|
||||
# Whether the file is publicly listable. Someone with knowledge of the ID
|
||||
# will still be able to view it, however.
|
||||
public: Boolean
|
||||
|
||||
# The file's name
|
||||
name: String
|
||||
}
|
||||
@@ -1,132 +0,0 @@
|
||||
# A Log is the "file" of an RP session
|
||||
type Log {
|
||||
# A unique identifier for the log.
|
||||
id: String!
|
||||
|
||||
# A secondary unique identifier for the log. This is a lot shorter and more suitable for storage when
|
||||
# the link doesn't need to be as expressive.
|
||||
shortId: String!
|
||||
|
||||
# The date for a log.
|
||||
date: String!
|
||||
|
||||
# The channel of a log.
|
||||
channelName: String!
|
||||
|
||||
# Information about the channel this log is in.
|
||||
channel: Channel!
|
||||
|
||||
# The session's title.
|
||||
title: String!
|
||||
|
||||
# The log's event, which is the same as the tags in the previous logbot site.
|
||||
# Empty string means that it's no event.
|
||||
event: String!
|
||||
|
||||
# The description of a session, which is empty if unset.
|
||||
description: String!
|
||||
|
||||
# Whether the log session is open.
|
||||
open: Boolean!
|
||||
|
||||
# The characters involved in the log file.
|
||||
characters: [Character!]!
|
||||
|
||||
# The posts of the logfile, which can be filtered by kinds.
|
||||
posts(kinds:[String!]): [Post!]!
|
||||
}
|
||||
|
||||
# Filter for logs query
|
||||
input LogsFilter {
|
||||
# Channels to limit results to (inclusive)
|
||||
channels: [String!]
|
||||
|
||||
# Events to limit results to (inclusive)
|
||||
events: [String!]
|
||||
|
||||
# Characters to limit results to (exclusive)
|
||||
characters: [String!]
|
||||
|
||||
# Search post content
|
||||
search: String
|
||||
|
||||
# Limit by whether it's open or not
|
||||
open: Boolean
|
||||
|
||||
# Limit the amount of results you get back
|
||||
limit: Int
|
||||
}
|
||||
|
||||
# Input for addLog mutation
|
||||
input LogAddInput {
|
||||
# The date of the log, in RFC3339 format with up to nanosecond precision
|
||||
date: String!
|
||||
|
||||
# The channel where the log is set
|
||||
channel: String!
|
||||
|
||||
# Optional: The log title
|
||||
title: String
|
||||
|
||||
# Optional: Whether the log is open
|
||||
open: Boolean
|
||||
|
||||
# Optional: The log event name
|
||||
event: String
|
||||
|
||||
# Optional: A short description of the log
|
||||
description: String
|
||||
}
|
||||
|
||||
# Input for addLog mutation
|
||||
input LogEditInput {
|
||||
# The id of the log
|
||||
id: String!
|
||||
|
||||
# The log title
|
||||
title: String
|
||||
|
||||
# The log event name
|
||||
event: String
|
||||
|
||||
# A short description of the log
|
||||
description: String
|
||||
|
||||
# Open/close the log
|
||||
open: Boolean
|
||||
}
|
||||
|
||||
# A LogHeader is a cut-down version of Log that does not allow getting the actual posts.
|
||||
type LogHeader {
|
||||
# A unique identifier for the log.
|
||||
id: String!
|
||||
|
||||
# A secondary unique identifier for the log. This is a lot shorter and more suitable for storage when
|
||||
# the link doesn't need to be as expressive.
|
||||
shortId: String!
|
||||
|
||||
# The date for a log.
|
||||
date: String!
|
||||
|
||||
# The channel name of a log.
|
||||
channelName: String!
|
||||
|
||||
# Information about the channel this log is in.
|
||||
channel: Channel!
|
||||
|
||||
# The session's title.
|
||||
title: String!
|
||||
|
||||
# The log's event, which is the same as the tags in the previous logbot site.
|
||||
# Empty string means that it's no event.
|
||||
event: String!
|
||||
|
||||
# The description of a session, which is empty if unset.
|
||||
description: String!
|
||||
|
||||
# Whether the log session is open.
|
||||
open: Boolean!
|
||||
|
||||
# The characters involved in the log file.
|
||||
characters: [Character!]!
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
# A Post is a part of a log
|
||||
type Post {
|
||||
# The post's ID
|
||||
id: String!
|
||||
|
||||
# The post's Log ID. This is the closest thing to a link back since this API graph doesn't have any cycles.
|
||||
logId: String!
|
||||
|
||||
# The date and time of posting
|
||||
time: String!
|
||||
|
||||
# The kind of post this is. Only "text", "scene" and "action" are RP, while others are annotations and 'commands'.
|
||||
kind: String!
|
||||
|
||||
# The character nick
|
||||
nick: String!
|
||||
|
||||
# The post's text, which purpose depends on the kind
|
||||
text: String!
|
||||
|
||||
# The post's position, used for reordering
|
||||
position: Int!
|
||||
}
|
||||
|
||||
# Input for the addPost mutation
|
||||
input AddPostInput {
|
||||
# The log's ID that this post should be a part of
|
||||
logId: String!
|
||||
|
||||
# The date and time of posting, in a RFC3339 format with up to a nanosecond's precision
|
||||
time: String!
|
||||
|
||||
# The kind of post this is. Only "text", "scene" and "action" are RP, while others are annotations and 'commands'.
|
||||
kind: String!
|
||||
|
||||
# The character nick, or command invoker for non-RP stuff
|
||||
nick: String!
|
||||
|
||||
# The post's text, which purpose depends on the kind
|
||||
text: String!
|
||||
}
|
||||
|
||||
# Input for the editPost mutation
|
||||
input EditPostInput {
|
||||
# The Post ID
|
||||
id: String!
|
||||
|
||||
# The date and time of posting, in a RFC3339 format with up to a nanosecond's precision
|
||||
time: String
|
||||
|
||||
# The kind of post this is. Only "text", "scene" and "action" are RP, while others are annotations and 'commands'.
|
||||
kind: String
|
||||
|
||||
# The character nick, or command invoker for non-RP stuff
|
||||
nick: String
|
||||
|
||||
# The post's text, which purpose depends on the kind
|
||||
text: String
|
||||
}
|
||||
|
||||
# Input for the movePost mutation
|
||||
input MovePostInput {
|
||||
# The Post ID
|
||||
id: String!
|
||||
|
||||
# Target index
|
||||
toPosition: Int!
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
# A Story is a piece of content that, unlike wiki articles, are not something that should be ordered by time instead of title. It can
|
||||
# contain multiple chapters by one or more autohrs
|
||||
type Story {
|
||||
# The story's ID
|
||||
id: String!
|
||||
|
||||
# The story's name, which will show up in the lists.
|
||||
name: String!
|
||||
|
||||
# The story's author
|
||||
author: String!
|
||||
|
||||
# Whether other users may add/edit chapters to the story.
|
||||
open: Boolean!
|
||||
|
||||
# Whether users without a direct link can find this story.
|
||||
listed: Boolean!
|
||||
|
||||
# The category of the story
|
||||
category: StoryCategory!
|
||||
|
||||
# The tags for this tory
|
||||
tags: [Tag!]!
|
||||
|
||||
# The chapters of this story
|
||||
chapters: [Chapter!]!
|
||||
|
||||
# The date the story was created (RFC3339 format).
|
||||
createdDate: String!
|
||||
|
||||
# The date the story is set in (RFC3339 format).
|
||||
fictionalDate: String!
|
||||
|
||||
# The date of the last major update to the story (RFC3339 format). This being bumped means a new chapter has been added.
|
||||
updatedDate: String!
|
||||
}
|
||||
|
||||
# Filter for stories query.
|
||||
input StoriesFilter {
|
||||
# What author to query for
|
||||
author: String
|
||||
|
||||
# What category to query for
|
||||
category: StoryCategory
|
||||
|
||||
# What tags to query for
|
||||
tags: [TagInput!]
|
||||
|
||||
# If true, it will only show unlisted page you have access to
|
||||
unlisted: Boolean
|
||||
|
||||
# Whether the page is open for additions by other users
|
||||
open: Boolean
|
||||
|
||||
# The earliest fictionalDate
|
||||
earliestFictionalDate: String
|
||||
|
||||
# The latest fictionalDate
|
||||
latestFictionalDate: String
|
||||
|
||||
# The max amount of stories to get (default: 30)
|
||||
limit: Int
|
||||
}
|
||||
|
||||
# Input for the addStory mutation
|
||||
input StoryAddInput {
|
||||
# Set the name of the story, which will show up as the title, and as a suggestion for
|
||||
# the first chapter being added.
|
||||
name: String!
|
||||
|
||||
# Set the category for the new story.
|
||||
category: StoryCategory!
|
||||
|
||||
# Add the story under another name. This requires the story.add permission, and should not be
|
||||
# abused. The action will be logged with the actual creator's user ID.
|
||||
author: String
|
||||
|
||||
# Allow other users to post chapters to the story.
|
||||
open: Boolean
|
||||
|
||||
# Allow other users to see this page in any lists or search results.
|
||||
listed: Boolean
|
||||
|
||||
# Set which tags the story should have.
|
||||
tags: [TagInput!]
|
||||
|
||||
# Set the fictional date of the story (RFC3339 format).
|
||||
fictionalDate: String
|
||||
}
|
||||
|
||||
# Input for the editStory mutation
|
||||
input StoryEditInput {
|
||||
# What story to edit
|
||||
id: String!
|
||||
|
||||
# Set the name of the story, which will show up as the title, and as a suggestion for
|
||||
# the first chapter being added.
|
||||
name: String
|
||||
|
||||
# Set the category for the new story.
|
||||
category: StoryCategory
|
||||
|
||||
# Add the story under another name. This requires the story.add permission, and should not be
|
||||
# abused. The action will be logged with the actual creator's user ID.
|
||||
author: String
|
||||
|
||||
# Change whether to allow others to add chapters
|
||||
open: Boolean
|
||||
|
||||
# Change whether to show this story in the list and search results
|
||||
listed: Boolean
|
||||
|
||||
# Set the fictional date of the story (RFC3339 format).
|
||||
fictionalDate: String
|
||||
}
|
||||
|
||||
# Input for the addStoryTag mutation
|
||||
input StoryTagAddInput {
|
||||
# What story to add the tag to.
|
||||
id: String!
|
||||
|
||||
# The tag to add.
|
||||
tag: TagInput!
|
||||
}
|
||||
|
||||
# Input for the removeStoryTag mutation
|
||||
input StoryTagRemoveInput {
|
||||
# What story to remove the tag from.
|
||||
id: String!
|
||||
|
||||
# The tag to remove.
|
||||
tag: TagInput!
|
||||
}
|
||||
|
||||
# Possible values for Story.category
|
||||
enum StoryCategory {
|
||||
# General information
|
||||
Info
|
||||
|
||||
# News stories
|
||||
News
|
||||
|
||||
# Description and content of a document or item
|
||||
Document
|
||||
|
||||
# Information about something going on in the background that may or may not inform RP
|
||||
Background
|
||||
|
||||
# A short story
|
||||
Story
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
# A Tag is a means of associating stories that have details in common with one another.
|
||||
type Tag {
|
||||
# The tag's kind
|
||||
kind: TagKind!
|
||||
|
||||
# The tag's name
|
||||
name: String!
|
||||
}
|
||||
|
||||
# A Tag is a means of associating stories that have details in common with one another.
|
||||
input TagInput {
|
||||
# The tag's kind
|
||||
kind: TagKind!
|
||||
|
||||
# The tag's name
|
||||
name: String!
|
||||
}
|
||||
|
||||
# Allowed values for Tag.kind
|
||||
enum TagKind {
|
||||
# An organization is a catch all term for in-universe corporations, teams, groups, cults, forces, etc...
|
||||
Organization
|
||||
|
||||
# A character tag should have the exact full name of the character.
|
||||
Character
|
||||
|
||||
# A location is anything from a planet to an establishment. This may overlap with an organization, and if so, both
|
||||
# kinds of tags should be used.
|
||||
Location
|
||||
|
||||
# An event is a plot or a part of a plot.
|
||||
Event
|
||||
|
||||
# None of the above, but it does still tie multiple stories together. The new story/chapter format may obsolete this tag kind.
|
||||
Series
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
# The User type is for interacting with user options and settings
|
||||
type User {
|
||||
# Their username
|
||||
id: String!
|
||||
|
||||
# Their permission
|
||||
permissions: [String!]!
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
package change
|
||||
|
||||
import (
|
||||
"log"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/model/counter"
|
||||
|
||||
"git.aiterp.net/rpdata/api/internal/store"
|
||||
"github.com/globalsign/mgo"
|
||||
)
|
||||
|
||||
var collection *mgo.Collection
|
||||
|
||||
// A Change represents a change in any other model
|
||||
type Change struct {
|
||||
ID int `bson:"_id" json:"id"`
|
||||
Time time.Time `bson:"time" json:"time"`
|
||||
Model string `bson:"model" json:"model"`
|
||||
Op string `bson:"op" json:"op"`
|
||||
Author string `bson:"author,omitempty" json:"author,omitempty"`
|
||||
ObjectID string `bson:"objectId,omitempty" json:"objectId,omitempty"`
|
||||
Data interface{} `bson:"data,omitempty" json:"data,omitempty"`
|
||||
}
|
||||
|
||||
// PublicModels lists which models can be listed in bulk by anyone.
|
||||
var PublicModels = []string{
|
||||
"Character",
|
||||
"Log",
|
||||
"Post",
|
||||
}
|
||||
|
||||
var submitMutex sync.Mutex
|
||||
|
||||
// Submit submits a change to the history.
|
||||
func Submit(model, op, author, objectID string, data interface{}) (Change, error) {
|
||||
submitMutex.Lock()
|
||||
defer submitMutex.Unlock()
|
||||
|
||||
index, err := counter.Next("auto_increment", "Change")
|
||||
if err != nil {
|
||||
return Change{}, err
|
||||
}
|
||||
|
||||
change := Change{
|
||||
ID: index,
|
||||
Time: time.Now(),
|
||||
Model: model,
|
||||
Op: op,
|
||||
Author: author,
|
||||
ObjectID: objectID,
|
||||
Data: data,
|
||||
}
|
||||
|
||||
Timeline.push(change)
|
||||
|
||||
err = collection.Insert(&change)
|
||||
if err != nil {
|
||||
return Change{}, err
|
||||
}
|
||||
|
||||
return change, err
|
||||
}
|
||||
|
||||
// FindID gets a change by ID
|
||||
func FindID(id int) (Change, error) {
|
||||
change := Change{}
|
||||
err := collection.FindId(id).One(&change)
|
||||
if err != nil {
|
||||
return Change{}, err
|
||||
}
|
||||
|
||||
return change, nil
|
||||
}
|
||||
|
||||
// List gets all changes in ascending order
|
||||
func List() ([]Change, error) {
|
||||
changes := make([]Change, 0, 64)
|
||||
err := collection.Find(nil).Sort("_id").All(&changes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return changes, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
store.HandleInit(func(db *mgo.Database) {
|
||||
collection = db.C("common.history")
|
||||
|
||||
collection.EnsureIndexKey("model")
|
||||
collection.EnsureIndexKey("author")
|
||||
collection.EnsureIndexKey("objectId")
|
||||
|
||||
err := collection.EnsureIndex(mgo.Index{
|
||||
Name: "expiry",
|
||||
Key: []string{"time"},
|
||||
ExpireAfter: time.Hour * 336,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
package change
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sync"
|
||||
|
||||
"github.com/globalsign/mgo"
|
||||
)
|
||||
|
||||
// ErrInvalidIndex is returned when a timeline subscriber tries to get a value
|
||||
// with a negative id
|
||||
var ErrInvalidIndex = errors.New("change.timeline: Invalid ID")
|
||||
|
||||
// ErrWaitRequired is returned when a timeline subscriber requests an entry that
|
||||
// has not yet been pushed
|
||||
var ErrWaitRequired = errors.New("change.timeline: Waiting required")
|
||||
|
||||
// ErrExpired is returned when a timeline subscriber requests a change that happened
|
||||
// too long ago for it to be in the database.
|
||||
var ErrExpired = errors.New("change.timeline: Change has expired")
|
||||
|
||||
type timeline struct {
|
||||
mutex sync.Mutex
|
||||
firstIndex int64
|
||||
currentID int64
|
||||
cache []Change
|
||||
notifyCh chan struct{}
|
||||
}
|
||||
|
||||
func (timeline *timeline) Get(ctx context.Context, id int64) (Change, error) {
|
||||
change, err := timeline.get(id, false)
|
||||
if err == ErrWaitRequired {
|
||||
if err := timeline.wait(ctx); err != nil {
|
||||
return Change{}, err
|
||||
}
|
||||
|
||||
return timeline.get(id, true)
|
||||
} else if err == mgo.ErrNotFound {
|
||||
return Change{}, ErrExpired
|
||||
}
|
||||
|
||||
return change, nil
|
||||
}
|
||||
|
||||
func (timeline *timeline) push(change Change) {
|
||||
timeline.mutex.Lock()
|
||||
timeline.cache = append(timeline.cache, change)
|
||||
if len(timeline.cache) > 128 {
|
||||
copy(timeline.cache, timeline.cache[32:])
|
||||
timeline.cache = timeline.cache[:len(timeline.cache)-32]
|
||||
}
|
||||
|
||||
// Only update the currentID if this is more recent than the existing ones
|
||||
if int64(change.ID) > timeline.currentID {
|
||||
timeline.currentID = int64(change.ID)
|
||||
}
|
||||
|
||||
if timeline.notifyCh != nil {
|
||||
close(timeline.notifyCh)
|
||||
timeline.notifyCh = nil
|
||||
}
|
||||
timeline.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (timeline *timeline) get(id int64, hasWaited bool) (Change, error) {
|
||||
if id < 0 {
|
||||
return Change{}, ErrInvalidIndex
|
||||
}
|
||||
|
||||
timeline.mutex.Lock()
|
||||
if !hasWaited && id > timeline.currentID {
|
||||
timeline.mutex.Unlock()
|
||||
return Change{}, ErrWaitRequired
|
||||
}
|
||||
|
||||
for _, change := range timeline.cache {
|
||||
if change.ID == int(id) {
|
||||
timeline.mutex.Unlock()
|
||||
return change, nil
|
||||
}
|
||||
}
|
||||
timeline.mutex.Unlock()
|
||||
|
||||
return FindID(int(id))
|
||||
}
|
||||
|
||||
func (timeline *timeline) wait(ctx context.Context) error {
|
||||
timeline.mutex.Lock()
|
||||
if timeline.notifyCh == nil {
|
||||
timeline.notifyCh = make(chan struct{})
|
||||
}
|
||||
|
||||
ch := timeline.notifyCh
|
||||
timeline.mutex.Unlock()
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
case <-ch:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Timeline has operations for subscribing to changes in real time
|
||||
var Timeline = &timeline{}
|
||||
|
||||
// InitializeTimeline fills in the timeline with existing entries
|
||||
func InitializeTimeline() {
|
||||
changes, err := List()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, change := range changes {
|
||||
Timeline.push(change)
|
||||
}
|
||||
}
|
||||
@@ -1,253 +0,0 @@
|
||||
package file
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"io"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/internal/store"
|
||||
"github.com/globalsign/mgo"
|
||||
"github.com/globalsign/mgo/bson"
|
||||
)
|
||||
|
||||
var fileCollection *mgo.Collection
|
||||
|
||||
// A File is a record of a file stored in the Space.
|
||||
type File struct {
|
||||
ID string `bson:"_id" json:"id"`
|
||||
Time time.Time `bson:"time" json:"time"`
|
||||
Kind string `bson:"kind" json:"kind"`
|
||||
Public bool `bson:"public" json:"public"`
|
||||
Name string `bson:"name" json:"name"`
|
||||
MimeType string `bson:"mimeType" json:"mimeType"`
|
||||
Size int64 `bson:"size" json:"size"`
|
||||
Author string `bson:"author" json:"author"`
|
||||
URL string `bson:"url,omitempty" json:"url,omitempty"`
|
||||
}
|
||||
|
||||
// Edit edits the file, changing up to both the two mutable properties
|
||||
func (file *File) Edit(name *string, public *bool) error {
|
||||
changes := bson.M{}
|
||||
changedFile := *file
|
||||
|
||||
if name != nil && *name != file.Name {
|
||||
changes["name"] = *name
|
||||
changedFile.Name = *name
|
||||
}
|
||||
if public != nil && *public != file.Public {
|
||||
changes["public"] = *public
|
||||
changedFile.Public = *public
|
||||
}
|
||||
|
||||
if len(changes) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
err := fileCollection.UpdateId(file.ID, bson.M{"$set": changes})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*file = changedFile
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete removes the file information from the database, and deletes the file.
|
||||
func (file *File) Delete() error {
|
||||
err := fileCollection.RemoveId(file.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if file.Kind == "upload" {
|
||||
err = store.RemoveFile("files", file.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
file.URL = ""
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Insert manually inserts file information into the database. This should never, ever be API accessible
|
||||
func Insert(name, kind, mimeType, author string, time time.Time, size int64, url string) (File, error) {
|
||||
file := File{
|
||||
ID: makeFileID(),
|
||||
Kind: kind,
|
||||
Time: time,
|
||||
Public: false,
|
||||
Author: author,
|
||||
Name: name,
|
||||
MimeType: mimeType,
|
||||
Size: size,
|
||||
URL: url,
|
||||
}
|
||||
|
||||
err := fileCollection.Insert(file)
|
||||
if err != nil {
|
||||
return File{}, err
|
||||
}
|
||||
|
||||
return file, nil
|
||||
}
|
||||
|
||||
// Upload adds a file to the space.
|
||||
func Upload(ctx context.Context, name, mimeType, author string, size int64, input io.Reader) (File, error) {
|
||||
if !allowdMimeTypes[mimeType] {
|
||||
return File{}, errors.New("File type not allowed:" + mimeType)
|
||||
}
|
||||
|
||||
if name == "" {
|
||||
date := time.Now().UTC().Format("Jan 02 2006 15:04:05 MST")
|
||||
name = "Unnamed file (" + date + ")"
|
||||
}
|
||||
|
||||
if mimeType == "" {
|
||||
mimeType = "binary/octet-stream"
|
||||
}
|
||||
|
||||
id := makeFileID()
|
||||
|
||||
path, err := store.UploadFile(ctx, "files", id, mimeType, input, size)
|
||||
if err != nil {
|
||||
return File{}, err
|
||||
}
|
||||
|
||||
file := File{
|
||||
ID: id,
|
||||
Kind: "upload",
|
||||
Time: time.Now(),
|
||||
Public: false,
|
||||
Author: author,
|
||||
Name: name,
|
||||
MimeType: mimeType,
|
||||
Size: size,
|
||||
URL: store.URLFromPath(path),
|
||||
}
|
||||
|
||||
err = fileCollection.Insert(file)
|
||||
if err != nil {
|
||||
return File{}, err
|
||||
}
|
||||
|
||||
return file, nil
|
||||
}
|
||||
|
||||
// FindID finds a file by ID
|
||||
func FindID(id string) (File, error) {
|
||||
file := File{}
|
||||
|
||||
err := fileCollection.FindId(id).One(&file)
|
||||
if err != nil {
|
||||
return File{}, err
|
||||
}
|
||||
|
||||
return file, nil
|
||||
}
|
||||
|
||||
// FindName finds a file by kind, name and author
|
||||
func FindName(kind string, name string, author string) (File, error) {
|
||||
query := bson.M{"kind": kind, "name": name, "author": author}
|
||||
file := File{}
|
||||
|
||||
err := fileCollection.Find(query).One(&file)
|
||||
if err != nil {
|
||||
return File{}, err
|
||||
}
|
||||
|
||||
return file, nil
|
||||
}
|
||||
|
||||
// List lists files according to the standard lookup. By default it's just the author's own files,
|
||||
// but if `public` is true it will alos include files made public by other authors. If `mimeTypes` contains
|
||||
// any, it will limit the results to that. If `author` is empty, it will only list public files
|
||||
func List(author string, public *bool, mimeTypes []string) ([]File, error) {
|
||||
query := bson.M{}
|
||||
|
||||
if author != "" {
|
||||
if public != nil {
|
||||
if *public == false {
|
||||
query["author"] = author
|
||||
}
|
||||
|
||||
query["public"] = *public
|
||||
} else {
|
||||
query["author"] = author
|
||||
}
|
||||
} else {
|
||||
if public != nil && *public == false {
|
||||
return nil, errors.New("You cannot")
|
||||
}
|
||||
|
||||
query["public"] = true
|
||||
}
|
||||
|
||||
if len(mimeTypes) > 0 {
|
||||
query["mimeTypes"] = bson.M{"$in": mimeTypes}
|
||||
}
|
||||
|
||||
return listFiles(query)
|
||||
}
|
||||
|
||||
func listFiles(query interface{}) ([]File, error) {
|
||||
list := make([]File, 0, 32)
|
||||
|
||||
err := fileCollection.Find(query).Sort("-time").All(&list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// makeFileID makes a random file ID that's 32 characters long
|
||||
func makeFileID() string {
|
||||
result := "F" + strconv.FormatInt(time.Now().UnixNano(), 36)
|
||||
offset := 0
|
||||
data := make([]byte, 32)
|
||||
|
||||
rand.Read(data)
|
||||
for len(result) < 32 {
|
||||
result += strconv.FormatUint(binary.LittleEndian.Uint64(data[offset:]), 36)
|
||||
offset += 8
|
||||
|
||||
if offset >= 32 {
|
||||
rand.Read(data)
|
||||
offset = 0
|
||||
}
|
||||
}
|
||||
|
||||
return result[:32]
|
||||
}
|
||||
|
||||
func init() {
|
||||
store.HandleInit(func(db *mgo.Database) {
|
||||
fileCollection = db.C("file.headers")
|
||||
|
||||
fileCollection.EnsureIndexKey("author")
|
||||
fileCollection.EnsureIndexKey("public")
|
||||
fileCollection.EnsureIndexKey("kind", "name", "author")
|
||||
fileCollection.EnsureIndexKey("author", "public")
|
||||
fileCollection.EnsureIndexKey("kind")
|
||||
})
|
||||
}
|
||||
|
||||
var allowdMimeTypes = map[string]bool{
|
||||
"": false,
|
||||
"image/jpeg": true,
|
||||
"image/png": true,
|
||||
"image/gif": true,
|
||||
"text/plain": true,
|
||||
"application/json": true,
|
||||
"application/pdf": false,
|
||||
"binary/octet-stream": false,
|
||||
"video/mp4": false,
|
||||
"audio/mp3": false,
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// ChangeModel describes a model related to the change.
|
||||
type ChangeModel string
|
||||
|
||||
const (
|
||||
// ChangeModelCharacter is a value of ChangeModel
|
||||
ChangeModelCharacter ChangeModel = "Character"
|
||||
// ChangeModelChannel is a value of ChangeModel
|
||||
ChangeModelChannel ChangeModel = "Channel"
|
||||
// ChangeModelLog is a value of ChangeModel
|
||||
ChangeModelLog ChangeModel = "Log"
|
||||
// ChangeModelPost is a value of ChangeModel
|
||||
ChangeModelPost ChangeModel = "Post"
|
||||
// ChangeModelStory is a value of ChangeModel
|
||||
ChangeModelStory ChangeModel = "Story"
|
||||
// ChangeModelTag is a value of ChangeModel
|
||||
ChangeModelTag ChangeModel = "Tag"
|
||||
// ChangeModelChapter is a value of ChangeModel
|
||||
ChangeModelChapter ChangeModel = "Chapter"
|
||||
)
|
||||
|
||||
// IsValid returns true if the underlying string is one of the correct values.
|
||||
func (e ChangeModel) IsValid() bool {
|
||||
switch e {
|
||||
case ChangeModelCharacter, ChangeModelChannel, ChangeModelLog, ChangeModelPost, ChangeModelStory, ChangeModelTag, ChangeModelChapter:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (e ChangeModel) String() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
// UnmarshalGQL unmarshals the underlying graphql value.
|
||||
func (e *ChangeModel) UnmarshalGQL(v interface{}) error {
|
||||
str, ok := v.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("enums must be strings")
|
||||
}
|
||||
|
||||
*e = ChangeModel(str)
|
||||
if !e.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid ChangeModel", str)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalGQL marshals the underlying graphql value.
|
||||
func (e ChangeModel) MarshalGQL(w io.Writer) {
|
||||
fmt.Fprint(w, strconv.Quote(e.String()))
|
||||
}
|
||||
+32
-8
@@ -4,30 +4,54 @@ import "time"
|
||||
|
||||
// Change represents a change in the rpdata history through the API.
|
||||
type Change struct {
|
||||
ID string `bson:"_id"`
|
||||
Model string `bson:"model"`
|
||||
Op string `bson:"op"`
|
||||
Author string `bson:"author"`
|
||||
Date time.Time `bson:"date"`
|
||||
ID string `bson:"_id"`
|
||||
Model ChangeModel `bson:"model"`
|
||||
Op string `bson:"op"`
|
||||
Author string `bson:"author"`
|
||||
Listed bool `bson:"listed"`
|
||||
Keys []ChangeKey `bson:"keys"`
|
||||
Date time.Time `bson:"date"`
|
||||
|
||||
Logs []Log `bson:"logs"`
|
||||
Characters []Character `bson:"characters"`
|
||||
Channels []Channel `bson:"channels"`
|
||||
Posts []Post `bson:"posts"`
|
||||
Stories []Story `bson:"stories"`
|
||||
Tags []Tag `bson:"tags"`
|
||||
Chapters []Chapter `bson:"chapters"`
|
||||
}
|
||||
|
||||
// Data makes a combined, mixed array of all the models stored in this change.
|
||||
func (change *Change) Data() []interface{} {
|
||||
data := make([]interface{}, 0, len(change.Logs)+len(change.Characters)+len(change.Posts))
|
||||
// ChangeKey is a key for a change that can be used when subscribing to them.
|
||||
type ChangeKey struct {
|
||||
Model ChangeModel `bson:"model"`
|
||||
ID string `bson:"id"`
|
||||
}
|
||||
|
||||
// Objects makes a combined, mixed array of all the models stored in this change.
|
||||
func (change *Change) Objects() []interface{} {
|
||||
data := make([]interface{}, 0, len(change.Logs)+len(change.Characters)+len(change.Channels)+len(change.Posts)+len(change.Stories)+len(change.Tags)+len(change.Chapters))
|
||||
|
||||
for _, log := range change.Logs {
|
||||
data = append(data, log)
|
||||
}
|
||||
for _, channel := range change.Channels {
|
||||
data = append(data, channel)
|
||||
}
|
||||
for _, character := range change.Characters {
|
||||
data = append(data, character)
|
||||
}
|
||||
for _, post := range change.Posts {
|
||||
data = append(data, post)
|
||||
}
|
||||
for _, story := range change.Stories {
|
||||
data = append(data, story)
|
||||
}
|
||||
for _, tag := range change.Tags {
|
||||
data = append(data, tag)
|
||||
}
|
||||
for _, chapter := range change.Chapters {
|
||||
data = append(data, chapter)
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package changekeys
|
||||
|
||||
import "git.aiterp.net/rpdata/api/models"
|
||||
|
||||
// All makes a changelog that's (model, "*"). It's a helper to standardize it.
|
||||
func All(model string) models.ChangeKey {
|
||||
return models.ChangeKey{Model: models.ChangeModel(model), ID: "*"}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package changekeys
|
||||
|
||||
import "git.aiterp.net/rpdata/api/models"
|
||||
|
||||
// Listed is a helper for cases like []models.ChangeKey{changekeys.All("Logs"), changekeys.One(log)}
|
||||
func Listed(objects ...interface{}) []models.ChangeKey {
|
||||
keys := Many(objects)
|
||||
if len(keys) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return append(keys, All(keys[0].Model.String()))
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package changekeys
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
)
|
||||
|
||||
// Many returns a key set matching the input objects, but without the asterisk key. You may pass
|
||||
// a slice as an argument, for example (log, posts) and it will be flattened
|
||||
func Many(objects ...interface{}) []models.ChangeKey {
|
||||
keys := make([]models.ChangeKey, 0, len(objects))
|
||||
for _, object := range objects {
|
||||
if v := reflect.ValueOf(object); v.Kind() == reflect.Slice {
|
||||
elems := make([]interface{}, 0, v.Len())
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
elems = append(elems, v.Index(i).Interface())
|
||||
}
|
||||
|
||||
keys = append(keys, Many(elems...)...)
|
||||
} else {
|
||||
keys = append(keys, One(object))
|
||||
}
|
||||
}
|
||||
|
||||
return keys
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package changekeys_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models/changekeys"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
)
|
||||
|
||||
func TestMany(t *testing.T) {
|
||||
data := []interface{}{
|
||||
models.Log{ID: "Stuff"},
|
||||
[]interface{}{
|
||||
models.Post{ID: "P1"},
|
||||
models.Post{ID: "P2"},
|
||||
models.Post{ID: "P3"},
|
||||
[]interface{}{
|
||||
models.Post{ID: "P4"},
|
||||
models.Character{ID: "C17"},
|
||||
models.Channel{Name: "#Stuff"},
|
||||
},
|
||||
},
|
||||
models.Post{ID: "P5"},
|
||||
}
|
||||
|
||||
expectations := []models.ChangeKey{
|
||||
{Model: "Log", ID: "Stuff"},
|
||||
{Model: "Post", ID: "P1"},
|
||||
{Model: "Post", ID: "P2"},
|
||||
{Model: "Post", ID: "P3"},
|
||||
{Model: "Post", ID: "P4"},
|
||||
{Model: "Character", ID: "C17"},
|
||||
{Model: "Channel", ID: "#Stuff"},
|
||||
{Model: "Post", ID: "P5"},
|
||||
}
|
||||
|
||||
results := changekeys.Many(data...)
|
||||
|
||||
if len(results) != len(expectations) {
|
||||
t.Fatal("Incorrect result length")
|
||||
}
|
||||
|
||||
for i := range expectations {
|
||||
result := results[i]
|
||||
expectation := expectations[i]
|
||||
|
||||
if result.ID != expectation.ID || result.Model != expectation.Model {
|
||||
t.Errorf("Incorrect: actual(%#+v, %#+v) != expected(%#+v, %#+v)", result.Model, result.ID, expectation.Model, expectation.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMany(b *testing.B) {
|
||||
data := []interface{}{
|
||||
models.Log{ID: "Stuff"},
|
||||
[]interface{}{
|
||||
models.Post{ID: "P1"},
|
||||
models.Post{ID: "P2"},
|
||||
models.Post{ID: "P3"},
|
||||
models.Post{ID: "P4"},
|
||||
models.Post{ID: "P5"},
|
||||
models.Post{ID: "P6"},
|
||||
models.Post{ID: "P7"},
|
||||
models.Post{ID: "P8"},
|
||||
models.Post{ID: "P9"},
|
||||
models.Post{ID: "P10"},
|
||||
models.Post{ID: "P11"},
|
||||
},
|
||||
models.Character{ID: "C17"},
|
||||
models.Channel{Name: "#Stuff"},
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
|
||||
for n := 0; n < b.N; n++ {
|
||||
changekeys.Many(data...)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package changekeys
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
)
|
||||
|
||||
// One makes a ChangeKey for a model, or panics if it's not supported.
|
||||
func One(object interface{}) models.ChangeKey {
|
||||
switch v := object.(type) {
|
||||
case models.Post:
|
||||
return models.ChangeKey{Model: "Post", ID: v.ID}
|
||||
case models.Character:
|
||||
return models.ChangeKey{Model: "Character", ID: v.ID}
|
||||
case models.Channel:
|
||||
return models.ChangeKey{Model: "Channel", ID: v.Name}
|
||||
}
|
||||
|
||||
model := ""
|
||||
if t := reflect.TypeOf(object); t.Kind() == reflect.Ptr {
|
||||
model = t.Elem().Name()
|
||||
} else {
|
||||
model = t.Name()
|
||||
}
|
||||
|
||||
id := ""
|
||||
v := reflect.ValueOf(object)
|
||||
if f := v.FieldByName("ID"); f.Kind() == reflect.String {
|
||||
id = f.String()
|
||||
} else if f = v.FieldByName("Name"); f.Kind() == reflect.String {
|
||||
id = f.String()
|
||||
} else {
|
||||
panic("Unsupported model")
|
||||
}
|
||||
|
||||
return models.ChangeKey{Model: models.ChangeModel(model), ID: id}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package changekeys_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
"git.aiterp.net/rpdata/api/models/changekeys"
|
||||
)
|
||||
|
||||
func TestOne(t *testing.T) {
|
||||
table := []struct {
|
||||
Label string
|
||||
Input interface{}
|
||||
Output models.ChangeKey
|
||||
}{
|
||||
{
|
||||
"Character_C17",
|
||||
models.Character{ID: "C17"},
|
||||
models.ChangeKey{Model: "Character", ID: "C17"},
|
||||
},
|
||||
{
|
||||
"Channel_#Miner'sRespite",
|
||||
models.Channel{Name: "#Miner'sRespite"},
|
||||
models.ChangeKey{Model: "Channel", ID: "#Miner'sRespite"},
|
||||
},
|
||||
{
|
||||
"Log_2018-10-23_210303325_RedrockAgency",
|
||||
models.Log{ID: "2018-10-23_210303325_RedrockAgency", ShortID: "L807"},
|
||||
models.ChangeKey{Model: "Log", ID: "2018-10-23_210303325_RedrockAgency"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, row := range table {
|
||||
t.Run(row.Label, func(t *testing.T) {
|
||||
key := changekeys.One(row.Input)
|
||||
|
||||
if key.ID != row.Output.ID || key.Model != row.Output.Model {
|
||||
t.Errorf("Incorrect: actual(%#+v, %#+v) != expected(%#+v, %#+v)", key.Model, key.ID, row.Output.Model, row.Output.ID)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkOneHit(b *testing.B) {
|
||||
var post = models.Post{ID: "P123412341234123"}
|
||||
|
||||
for n := 0; n < b.N; n++ {
|
||||
changekeys.One(post)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkOneMiss(b *testing.B) {
|
||||
var story = models.Story{ID: "P123412341234123"}
|
||||
|
||||
for n := 0; n < b.N; n++ {
|
||||
changekeys.One(story)
|
||||
}
|
||||
}
|
||||
@@ -6,18 +6,28 @@ import (
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/internal/store"
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
"github.com/globalsign/mgo"
|
||||
"github.com/globalsign/mgo/bson"
|
||||
)
|
||||
|
||||
var collection *mgo.Collection
|
||||
var submitMutex sync.Mutex
|
||||
|
||||
func list(query bson.M, limit int) ([]models.Change, error) {
|
||||
changes := make([]models.Change, 0, 64)
|
||||
err := collection.Find(query).Limit(limit).Sort("date").All(&changes)
|
||||
|
||||
return changes, err
|
||||
}
|
||||
|
||||
func init() {
|
||||
store.HandleInit(func(db *mgo.Database) {
|
||||
collection = db.C("common.changes")
|
||||
|
||||
collection.EnsureIndexKey("date")
|
||||
collection.EnsureIndexKey("author")
|
||||
collection.EnsureIndexKey("keys")
|
||||
|
||||
err := collection.EnsureIndex(mgo.Index{
|
||||
Name: "expiry",
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package changes
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
"github.com/globalsign/mgo/bson"
|
||||
)
|
||||
|
||||
// Filter is a filter for changes.List.
|
||||
type Filter struct {
|
||||
Keys []models.ChangeKey
|
||||
EarliestDate *time.Time
|
||||
Limit *int
|
||||
}
|
||||
|
||||
// List lists changes.
|
||||
func List(filter *Filter) ([]models.Change, error) {
|
||||
query := bson.M{}
|
||||
limit := 0
|
||||
|
||||
if filter != nil {
|
||||
if filter.Limit != nil {
|
||||
limit = *filter.Limit
|
||||
}
|
||||
|
||||
if filter.Keys != nil {
|
||||
query["keys"] = bson.M{"$in": filter.Keys}
|
||||
} else {
|
||||
query["listed"] = true
|
||||
}
|
||||
|
||||
if filter.EarliestDate != nil {
|
||||
query["date"] = bson.M{"$gte": *filter.EarliestDate}
|
||||
}
|
||||
} else {
|
||||
query["listed"] = true
|
||||
limit = 256
|
||||
}
|
||||
|
||||
return list(query, limit)
|
||||
}
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
)
|
||||
|
||||
// Submit a change to the database
|
||||
func Submit(model, op, author string, objects ...interface{}) (models.Change, error) {
|
||||
// Submit a change to the database. The objects may be any supported model, or arrays.
|
||||
func Submit(model, op, author string, listed bool, keys []models.ChangeKey, objects ...interface{}) (models.Change, error) {
|
||||
submitMutex.Lock()
|
||||
defer submitMutex.Unlock()
|
||||
|
||||
@@ -18,22 +18,68 @@ func Submit(model, op, author string, objects ...interface{}) (models.Change, er
|
||||
return models.Change{}, err
|
||||
}
|
||||
|
||||
if !models.ChangeModel(model).IsValid() {
|
||||
panic("Invalid model")
|
||||
}
|
||||
|
||||
// Silently discard * keys on unlisted changes.
|
||||
if !listed {
|
||||
keysCopy := make([]models.ChangeKey, len(keys))
|
||||
copy(keysCopy, keys)
|
||||
keys = keysCopy
|
||||
|
||||
deletes := make([]int, 0, 1)
|
||||
for i, key := range keys {
|
||||
if key.ID == "*" {
|
||||
deletes = append(deletes, i-len(deletes))
|
||||
}
|
||||
}
|
||||
|
||||
for _, index := range deletes {
|
||||
keys = append(keys[:index], keys[index+1:]...)
|
||||
}
|
||||
}
|
||||
|
||||
change := models.Change{
|
||||
ID: "Change_" + strconv.Itoa(id),
|
||||
Model: model,
|
||||
Model: models.ChangeModel(model),
|
||||
Date: time.Now(),
|
||||
Op: op,
|
||||
Author: author,
|
||||
Keys: keys,
|
||||
Listed: listed,
|
||||
}
|
||||
|
||||
for _, object := range objects {
|
||||
switch object := object.(type) {
|
||||
case models.Log:
|
||||
change.Logs = append(change.Logs, object)
|
||||
case []models.Log:
|
||||
change.Logs = append(change.Logs, object...)
|
||||
case models.Character:
|
||||
change.Characters = append(change.Characters, object)
|
||||
case []models.Character:
|
||||
change.Characters = append(change.Characters, object...)
|
||||
case models.Channel:
|
||||
change.Channels = append(change.Channels, object)
|
||||
case []models.Channel:
|
||||
change.Channels = append(change.Channels, object...)
|
||||
case models.Post:
|
||||
change.Posts = append(change.Posts, object)
|
||||
case []models.Post:
|
||||
change.Posts = append(change.Posts, object...)
|
||||
case models.Story:
|
||||
change.Stories = append(change.Stories, object)
|
||||
case []models.Story:
|
||||
change.Stories = append(change.Stories, object...)
|
||||
case models.Tag:
|
||||
change.Tags = append(change.Tags, object)
|
||||
case []models.Tag:
|
||||
change.Tags = append(change.Tags, object...)
|
||||
case models.Chapter:
|
||||
change.Chapters = append(change.Chapters, object)
|
||||
case []models.Chapter:
|
||||
change.Chapters = append(change.Chapters, object...)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package chapters
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
"github.com/globalsign/mgo/bson"
|
||||
)
|
||||
|
||||
// Move updates the chapter, moving it to the given story.
|
||||
func Move(chapter models.Chapter, story models.Story) (models.Chapter, error) {
|
||||
now := time.Now()
|
||||
|
||||
err := collection.UpdateId(chapter.ID, bson.M{"$set": bson.M{"editedDate": now, "storyId": story.ID}})
|
||||
if err != nil {
|
||||
return models.Chapter{}, err
|
||||
}
|
||||
|
||||
chapter.EditedDate = now
|
||||
|
||||
if chapter.CreatedDate.After(story.UpdatedDate) {
|
||||
if err := storyCollection.UpdateId(story.ID, bson.M{"$set": bson.M{"updatedDate": chapter.CreatedDate}}); err == nil {
|
||||
story.UpdatedDate = chapter.CreatedDate
|
||||
}
|
||||
}
|
||||
|
||||
return chapter, nil
|
||||
}
|
||||
@@ -72,6 +72,8 @@ var allowdMimeTypes = map[string]bool{
|
||||
"image/jpeg": true,
|
||||
"image/png": true,
|
||||
"image/gif": true,
|
||||
"image/tiff": true,
|
||||
"image/tga": true,
|
||||
"text/plain": true,
|
||||
"application/json": true,
|
||||
"application/pdf": false,
|
||||
|
||||
@@ -9,3 +9,8 @@ import (
|
||||
func FindID(id string) (models.File, error) {
|
||||
return find(bson.M{"_id": id})
|
||||
}
|
||||
|
||||
// FindName finds a file by ID
|
||||
func FindName(kind, name, author string) (models.File, error) {
|
||||
return find(bson.M{"name": name, "kind": kind, "author": author})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package files
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
)
|
||||
|
||||
// Insert manually inserts file information into the database. This should never, ever be HTTP API accessible
|
||||
func Insert(name, kind, mimeType, author string, time time.Time, size int64, url string) (models.File, error) {
|
||||
file := models.File{
|
||||
ID: makeID(),
|
||||
Kind: kind,
|
||||
Time: time,
|
||||
Public: false,
|
||||
Author: author,
|
||||
Name: name,
|
||||
MimeType: mimeType,
|
||||
Size: size,
|
||||
URL: url,
|
||||
}
|
||||
|
||||
err := collection.Insert(file)
|
||||
if err != nil {
|
||||
return models.File{}, err
|
||||
}
|
||||
|
||||
return file, nil
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package files
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/internal/store"
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
)
|
||||
|
||||
// Upload adds a file to the space.
|
||||
func Upload(ctx context.Context, name, mimeType, author string, size int64, input io.Reader) (models.File, error) {
|
||||
if !allowdMimeTypes[mimeType] {
|
||||
return models.File{}, errors.New("File type not allowed:" + mimeType)
|
||||
}
|
||||
|
||||
if name == "" {
|
||||
date := time.Now().UTC().Format("Jan 02 2006 15:04:05 MST")
|
||||
name = "Unnamed file (" + date + ")"
|
||||
}
|
||||
if mimeType == "" {
|
||||
mimeType = "binary/octet-stream"
|
||||
}
|
||||
|
||||
id := makeID()
|
||||
|
||||
path, err := store.UploadFile(ctx, "files", id, mimeType, input, size)
|
||||
if err != nil {
|
||||
return models.File{}, err
|
||||
}
|
||||
|
||||
file := models.File{
|
||||
ID: id,
|
||||
Kind: "upload",
|
||||
Time: time.Now(),
|
||||
Public: false,
|
||||
Author: author,
|
||||
Name: name,
|
||||
MimeType: mimeType,
|
||||
Size: size,
|
||||
URL: store.URLFromPath(path),
|
||||
}
|
||||
|
||||
err = collection.Insert(file)
|
||||
if err != nil {
|
||||
return models.File{}, err
|
||||
}
|
||||
|
||||
return file, nil
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
# See https://help.github.com/ignore-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
@@ -1,14 +0,0 @@
|
||||
# User Interface
|
||||
|
||||
## Setup
|
||||
|
||||
This is a UI created with `create-react-app`, so the process of getting started on a new host is navigating to the directory and running these commands.
|
||||
|
||||
```sh
|
||||
npm install
|
||||
npm start
|
||||
```
|
||||
|
||||
## Release
|
||||
|
||||
This is built and packaged with the parent project.
|
||||
Generated
-12110
File diff suppressed because it is too large
Load Diff
@@ -1,34 +0,0 @@
|
||||
{
|
||||
"name": "rpdata-ui",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"ajv": "^6.5.2",
|
||||
"apollo-boost": "^0.1.10",
|
||||
"apollo-cache-inmemory": "^1.3.0-beta.6",
|
||||
"graphql": "^0.13.2",
|
||||
"graphql-tag": "^2.9.2",
|
||||
"moment": "^2.22.2",
|
||||
"pluralize": "^7.0.0",
|
||||
"react": "^16.4.1",
|
||||
"react-apollo": "^2.1.9",
|
||||
"react-dom": "^16.4.1",
|
||||
"react-router": "^4.3.1",
|
||||
"react-router-dom": "^4.3.1",
|
||||
"react-scripts": "1.1.4"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test --env=jsdom",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playlyfe/gql": "^2.6.0"
|
||||
},
|
||||
"proxy": {
|
||||
"/graphql": {
|
||||
"target": "http://10.32.7.1:17000"
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 62 KiB |
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user