Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
53a86c0b9c | ||
|
|
e0b93c6b4b | ||
|
|
1ea04f1577 | ||
|
|
17fd3c60f8 | ||
|
|
c5b62a42db |
@@ -75,11 +75,10 @@ func queryHandler() http.HandlerFunc {
|
|||||||
handler := handler.GraphQL(
|
handler := handler.GraphQL(
|
||||||
graph2.New(),
|
graph2.New(),
|
||||||
handler.RecoverFunc(func(ctx context.Context, err interface{}) error {
|
handler.RecoverFunc(func(ctx context.Context, err interface{}) error {
|
||||||
// send this panic somewhere
|
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
log.Println(string(debug.Stack()))
|
log.Println(string(debug.Stack()))
|
||||||
|
|
||||||
return fmt.Errorf("shit")
|
return fmt.Errorf("The server failed to serve your request due to an internal error, it has been logged")
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -125,10 +125,10 @@ func (r *mutationResolver) ImportLog(ctx context.Context, input input.LogImportI
|
|||||||
|
|
||||||
newLogs := make([]models.Log, 0, len(results))
|
newLogs := make([]models.Log, 0, len(results))
|
||||||
for _, result := range results {
|
for _, result := range results {
|
||||||
go func() {
|
go func(result logs.ImportedLog) {
|
||||||
changes.Submit("Log", "add", token.UserID, true, changekeys.Many(result.Log), result.Log)
|
changes.Submit("Log", "add", token.UserID, true, changekeys.Many(result.Log), result.Log)
|
||||||
changes.Submit("Post", "add", token.UserID, true, changekeys.Many(result.Log, result.Posts), result.Posts)
|
changes.Submit("Post", "add", token.UserID, true, changekeys.Many(result.Log, result.Posts), result.Posts)
|
||||||
}()
|
}(result)
|
||||||
|
|
||||||
log, err := logs.UpdateCharacters(result.Log, nil)
|
log, err := logs.UpdateCharacters(result.Log, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+16
-4
@@ -79,8 +79,14 @@ func (r *mutationResolver) AddStoryTag(ctx context.Context, input input.StoryTag
|
|||||||
return models.Story{}, errors.New("Story not found")
|
return models.Story{}, errors.New("Story not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !token.PermittedUser(story.Author, "member", "story.edit") {
|
if story.Open {
|
||||||
return models.Story{}, errors.New("You are not permitted to edit this story")
|
if !token.Permitted("member") {
|
||||||
|
return models.Story{}, errors.New("You are not permitted to edit this story")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if !token.PermittedUser(story.Author, "member", "story.edit") {
|
||||||
|
return models.Story{}, errors.New("You are not permitted to edit this story")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
story, err = stories.AddTag(story, input.Tag)
|
story, err = stories.AddTag(story, input.Tag)
|
||||||
@@ -101,8 +107,14 @@ func (r *mutationResolver) RemoveStoryTag(ctx context.Context, input input.Story
|
|||||||
return models.Story{}, errors.New("Story not found")
|
return models.Story{}, errors.New("Story not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !token.PermittedUser(story.Author, "member", "story.edit") {
|
if story.Open {
|
||||||
return models.Story{}, errors.New("You are not permitted to edit this story")
|
if !token.Permitted("member") {
|
||||||
|
return models.Story{}, errors.New("You are not permitted to edit this story")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if !token.PermittedUser(story.Author, "member", "story.edit") {
|
||||||
|
return models.Story{}, errors.New("You are not permitted to edit this story")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
story, err = stories.RemoveTag(story, input.Tag)
|
story, err = stories.RemoveTag(story, input.Tag)
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ var global *Config
|
|||||||
// Config is configuration
|
// Config is configuration
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Space struct {
|
Space struct {
|
||||||
|
Enabled bool `json:"enabled"`
|
||||||
Host string `json:"host"`
|
Host string `json:"host"`
|
||||||
AccessKey string `json:"accessKey"`
|
AccessKey string `json:"accessKey"`
|
||||||
SecretKey string `json:"secretKey"`
|
SecretKey string `json:"secretKey"`
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ func ParsePost(line string, date time.Time, prev models.Post) (models.Post, erro
|
|||||||
|
|
||||||
if line[tsEndIndex+2] == '*' {
|
if line[tsEndIndex+2] == '*' {
|
||||||
split := strings.SplitN(line[tsEndIndex+4:], " ", 2)
|
split := strings.SplitN(line[tsEndIndex+4:], " ", 2)
|
||||||
|
if len(split) == 1 {
|
||||||
|
return models.Post{}, ErrNotPost
|
||||||
|
}
|
||||||
|
|
||||||
post := models.Post{
|
post := models.Post{
|
||||||
ID: "UNASSIGNED",
|
ID: "UNASSIGNED",
|
||||||
@@ -70,6 +73,9 @@ func ParsePost(line string, date time.Time, prev models.Post) (models.Post, erro
|
|||||||
return post, nil
|
return post, nil
|
||||||
} else if line[tsEndIndex+2] == '<' {
|
} else if line[tsEndIndex+2] == '<' {
|
||||||
split := strings.SplitN(line[tsEndIndex+2:], " ", 2)
|
split := strings.SplitN(line[tsEndIndex+2:], " ", 2)
|
||||||
|
if len(split) == 1 {
|
||||||
|
return models.Post{}, ErrNotPost
|
||||||
|
}
|
||||||
|
|
||||||
post := models.Post{
|
post := models.Post{
|
||||||
ID: "UNASSIGNED",
|
ID: "UNASSIGNED",
|
||||||
|
|||||||
@@ -71,6 +71,10 @@ func TestParsePostErrors(t *testing.T) {
|
|||||||
{"[10] <Stuff> Things said.", mirclike.ErrNotPost},
|
{"[10] <Stuff> Things said.", mirclike.ErrNotPost},
|
||||||
{"[12:34:56:789] <Stuff> Things said.", nil},
|
{"[12:34:56:789] <Stuff> Things said.", nil},
|
||||||
{"[12:34:56.789] <Stuff> Things said.", mirclike.ErrNotPost},
|
{"[12:34:56.789] <Stuff> Things said.", mirclike.ErrNotPost},
|
||||||
|
{"[12:34] <Stuff>", mirclike.ErrNotPost},
|
||||||
|
{"[12:34] * Stuff", mirclike.ErrNotPost},
|
||||||
|
{"[12:34] =Scene=", mirclike.ErrNotPost},
|
||||||
|
{"[12:34] <=Scene=>", mirclike.ErrNotPost},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, row := range table {
|
for i, row := range table {
|
||||||
|
|||||||
@@ -26,9 +26,11 @@ func Init() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sconf := conf.Space
|
sconf := conf.Space
|
||||||
err = ConnectSpace(sconf.Host, sconf.AccessKey, sconf.SecretKey, sconf.Bucket, sconf.MaxSize, sconf.Root)
|
if sconf.Enabled {
|
||||||
if err != nil {
|
err = ConnectSpace(sconf.Host, sconf.AccessKey, sconf.SecretKey, sconf.Bucket, sconf.MaxSize, sconf.Root)
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hasInitialized = true
|
hasInitialized = true
|
||||||
|
|||||||
@@ -43,6 +43,10 @@ func ConnectSpace(host, accessKey, secretKey, bucket string, maxSize int64, root
|
|||||||
// UploadFile uploads the file to the space. This does not do any checks on it, so the endpoints should
|
// UploadFile uploads the file to the space. This does not do any checks on it, so the endpoints should
|
||||||
// ensure that's all okay.
|
// ensure that's all okay.
|
||||||
func UploadFile(ctx context.Context, folder string, name string, mimeType string, reader io.Reader, size int64) (string, error) {
|
func UploadFile(ctx context.Context, folder string, name string, mimeType string, reader io.Reader, size int64) (string, error) {
|
||||||
|
if spaceClient == nil {
|
||||||
|
return "", errors.New("This functionality is not enabled")
|
||||||
|
}
|
||||||
|
|
||||||
path := folder + "/" + name
|
path := folder + "/" + name
|
||||||
|
|
||||||
if size > spaceMaxSize {
|
if size > spaceMaxSize {
|
||||||
@@ -69,6 +73,10 @@ func UploadFile(ctx context.Context, folder string, name string, mimeType string
|
|||||||
|
|
||||||
// RemoveFile removes a file from the space
|
// RemoveFile removes a file from the space
|
||||||
func RemoveFile(folder string, name string) error {
|
func RemoveFile(folder string, name string) error {
|
||||||
|
if spaceClient == nil {
|
||||||
|
return errors.New("This functionality is not enabled")
|
||||||
|
}
|
||||||
|
|
||||||
path := folder + "/" + name
|
path := folder + "/" + name
|
||||||
|
|
||||||
return spaceClient.RemoveObject(spaceBucket, spaceRoot+"/"+path)
|
return spaceClient.RemoveObject(spaceBucket, spaceRoot+"/"+path)
|
||||||
@@ -76,6 +84,10 @@ func RemoveFile(folder string, name string) error {
|
|||||||
|
|
||||||
// DownloadFile opens a file for download, using the same path format as the UploadFile function. Remember to Close it!
|
// DownloadFile opens a file for download, using the same path format as the UploadFile function. Remember to Close it!
|
||||||
func DownloadFile(ctx context.Context, path string) (io.ReadCloser, error) {
|
func DownloadFile(ctx context.Context, path string) (io.ReadCloser, error) {
|
||||||
|
if spaceClient == nil {
|
||||||
|
return nil, errors.New("This functionality is not enabled")
|
||||||
|
}
|
||||||
|
|
||||||
return spaceClient.GetObjectWithContext(ctx, spaceBucket, spaceRoot+"/"+path, minio.GetObjectOptions{})
|
return spaceClient.GetObjectWithContext(ctx, spaceBucket, spaceRoot+"/"+path, minio.GetObjectOptions{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user