package queries import ( "context" "git.aiterp.net/rpdata/api/internal/auth" "git.aiterp.net/rpdata/api/models" "git.aiterp.net/rpdata/api/models/files" ) func (r *resolver) File(ctx context.Context, id string) (*models.File, error) { file, err := files.FindID(id) if err != nil { return nil, err } return &file, nil } func (r *resolver) Files(ctx context.Context, filter *files.Filter) ([]models.File, error) { token := auth.TokenFromContext(ctx) if filter == nil { filter = &files.Filter{} } // Only allow users to view public files that are not their own. if token != nil { if filter.Public == nil || *filter.Public == false { filter.Author = &token.UserID } } else { filter.Public = &trueValue } return files.List(filter) } var trueValue = true