52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package resolver
|
|
|
|
// This file will be automatically regenerated based on the schema, any resolver implementations
|
|
// will be copied through when generating and any unknown code will be moved to the end.
|
|
// Code generated by github.com/99designs/gqlgen version v0.17.72
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
pathlib "path"
|
|
|
|
graph "git.kmsign.ru/royalcat/tstor/server/src/delivery/graphql"
|
|
"github.com/99designs/gqlgen/graphql"
|
|
)
|
|
|
|
// UploadFile is the resolver for the uploadFile field.
|
|
func (r *mutationResolver) UploadFile(ctx context.Context, dir string, file graphql.Upload) (bool, error) {
|
|
dirInfo, err := r.SourceFS.Stat(dir)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
if !dirInfo.IsDir() {
|
|
return false, fmt.Errorf("path %s is not a directory", dir)
|
|
}
|
|
|
|
filename := pathlib.Join(dir, file.Filename)
|
|
target, err := r.SourceFS.OpenFile(filename, os.O_CREATE|os.O_WRONLY, os.ModePerm)
|
|
defer target.Close()
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
_, err = io.CopyN(target, file.File, file.Size)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
return true, nil
|
|
}
|
|
|
|
// DedupeStorage is the resolver for the dedupeStorage field.
|
|
func (r *mutationResolver) DedupeStorage(ctx context.Context) (int64, error) {
|
|
return 0, nil
|
|
}
|
|
|
|
// Mutation returns graph.MutationResolver implementation.
|
|
func (r *Resolver) Mutation() graph.MutationResolver { return &mutationResolver{r} }
|
|
|
|
type mutationResolver struct{ *Resolver }
|