Fix site_info, replace ID type in graphql queries
This commit is contained in:
parent
31da5e1c07
commit
364521958b
|
@ -20,14 +20,21 @@ func GetSiteInfo(db *gorm.DB) (*SiteInfo, error) {
|
|||
|
||||
var siteInfo SiteInfo
|
||||
|
||||
err := db.FirstOrCreate(&siteInfo, SiteInfo{
|
||||
if err := db.First(&siteInfo).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
siteInfo = SiteInfo{
|
||||
InitialSetup: true,
|
||||
PeriodicScanInterval: 0,
|
||||
ConcurrentWorkers: 3,
|
||||
}).Error
|
||||
if err != nil {
|
||||
}
|
||||
|
||||
if err := db.Create(&siteInfo).Error; err != nil {
|
||||
return nil, errors.Wrap(err, "initialize site_info")
|
||||
}
|
||||
} else {
|
||||
return nil, errors.Wrap(err, "get site info from database")
|
||||
}
|
||||
}
|
||||
|
||||
return &siteInfo, nil
|
||||
}
|
||||
|
|
|
@ -185,7 +185,7 @@ func VerifyTokenAndGetUser(db *gorm.DB, token string) (*User, error) {
|
|||
// }
|
||||
|
||||
var user User
|
||||
result = db.First(&user, accessToken.ID)
|
||||
result = db.First(&user, accessToken.UserID)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
"github.com/viktorstrate/photoview/api/graphql/models"
|
||||
"github.com/viktorstrate/photoview/api/scanner"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func (r *mutationResolver) ScanAll(ctx context.Context) (*models.ScannerResult, error) {
|
||||
|
@ -66,7 +67,7 @@ func (r *mutationResolver) SetScannerConcurrentWorkers(ctx context.Context, work
|
|||
return 0, errors.New("concurrent workers must at least be 1")
|
||||
}
|
||||
|
||||
if err := r.Database.Model(&models.SiteInfo{}).Update("concurrent_workers", workers).Error; err != nil {
|
||||
if err := r.Database.Session(&gorm.Session{AllowGlobalUpdate: true}).Model(&models.SiteInfo{}).Update("concurrent_workers", workers).Error; err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
|
|
|
@ -33,9 +33,10 @@ func CleanupMedia(db *gorm.DB, albumId int, albumMedia []*models.Media) []error
|
|||
|
||||
deleteErrors := make([]error, 0)
|
||||
|
||||
mediaIDs := make([]int, 0)
|
||||
for _, media := range mediaList {
|
||||
|
||||
// deletedMediaIDs = append(deletedMediaIDs, media.ID)
|
||||
mediaIDs = append(mediaIDs, media.ID)
|
||||
cachePath := path.Join(PhotoCache(), strconv.Itoa(int(albumId)), strconv.Itoa(int(media.ID)))
|
||||
err := os.RemoveAll(cachePath)
|
||||
if err != nil {
|
||||
|
@ -44,7 +45,7 @@ func CleanupMedia(db *gorm.DB, albumId int, albumMedia []*models.Media) []error
|
|||
|
||||
}
|
||||
|
||||
if err := db.Delete(&mediaList).Error; err != nil {
|
||||
if err := db.Where("id IN ?", mediaIDs).Delete(models.Media{}).Error; err != nil {
|
||||
deleteErrors = append(deleteErrors, errors.Wrap(err, "delete old media from database"))
|
||||
}
|
||||
|
||||
|
@ -69,23 +70,23 @@ func deleteOldUserAlbums(db *gorm.DB, scannedAlbums []*models.Album, user *model
|
|||
var albums []models.Album
|
||||
|
||||
albums_questions := strings.Repeat("MD5(?),", len(albumPaths))[:len(albumPaths)*7-1]
|
||||
if err := db.Where("album.owner_id = ? AND path_hash NOT IN ("+albums_questions+")", album_args...).Find(&albums).Error; err != nil {
|
||||
if err := db.Where("owner_id = ? AND path_hash NOT IN ("+albums_questions+")", album_args...).Find(&albums).Error; err != nil {
|
||||
return []error{errors.Wrap(err, "get albums to be deleted from database")}
|
||||
}
|
||||
|
||||
deleteErrors := make([]error, 0)
|
||||
|
||||
deleted_album_ids := make([]interface{}, 0)
|
||||
albumIDs := make([]int, 0)
|
||||
for _, album := range albums {
|
||||
deleted_album_ids = append(deleted_album_ids, album.ID)
|
||||
cache_path := path.Join("./photo_cache", strconv.Itoa(int(album.ID)))
|
||||
err := os.RemoveAll(cache_path)
|
||||
albumIDs = append(albumIDs, album.ID)
|
||||
cachePath := path.Join("./photo_cache", strconv.Itoa(int(album.ID)))
|
||||
err := os.RemoveAll(cachePath)
|
||||
if err != nil {
|
||||
deleteErrors = append(deleteErrors, errors.Wrapf(err, "delete unused cache folder (%s)", cache_path))
|
||||
deleteErrors = append(deleteErrors, errors.Wrapf(err, "delete unused cache folder (%s)", cachePath))
|
||||
}
|
||||
}
|
||||
|
||||
if err := db.Delete(&albums).Error; err != nil {
|
||||
if err := db.Where("id IN ?", albumIDs).Delete(models.Album{}).Error; err != nil {
|
||||
ScannerError("Could not delete old albums from database:\n%s\n", err)
|
||||
deleteErrors = append(deleteErrors, errors.Wrap(err, "delete old albums from database"))
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import Layout from '../../Layout'
|
|||
|
||||
const albumQuery = gql`
|
||||
query albumQuery(
|
||||
$id: Int!
|
||||
$id: ID!
|
||||
$onlyFavorites: Boolean
|
||||
$mediaOrderBy: String
|
||||
$mediaOrderDirection: OrderDirection
|
||||
|
|
|
@ -5,7 +5,7 @@ import { useLazyQuery } from '@apollo/client'
|
|||
import PresentView from '../../components/photoGallery/presentView/PresentView'
|
||||
|
||||
const QUERY_MEDIA = gql`
|
||||
query placePageQueryMedia($mediaIDs: [Int!]!) {
|
||||
query placePageQueryMedia($mediaIDs: [ID!]!) {
|
||||
mediaList(ids: $mediaIDs) {
|
||||
id
|
||||
title
|
||||
|
|
|
@ -13,7 +13,7 @@ import {
|
|||
|
||||
const updateUserMutation = gql`
|
||||
mutation updateUser(
|
||||
$id: Int!
|
||||
$id: ID!
|
||||
$username: String
|
||||
$rootPath: String
|
||||
$admin: Boolean
|
||||
|
@ -33,7 +33,7 @@ const updateUserMutation = gql`
|
|||
`
|
||||
|
||||
const deleteUserMutation = gql`
|
||||
mutation deleteUser($id: Int!) {
|
||||
mutation deleteUser($id: ID!) {
|
||||
deleteUser(id: $id) {
|
||||
id
|
||||
username
|
||||
|
@ -42,7 +42,7 @@ const deleteUserMutation = gql`
|
|||
`
|
||||
|
||||
const changeUserPasswordMutation = gql`
|
||||
mutation changeUserPassword($userId: Int!, $password: String!) {
|
||||
mutation changeUserPassword($userId: ID!, $password: String!) {
|
||||
updateUser(id: $userId, password: $password) {
|
||||
id
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ const changeUserPasswordMutation = gql`
|
|||
`
|
||||
|
||||
const scanUserMutation = gql`
|
||||
mutation scanUser($userId: Int!) {
|
||||
mutation scanUser($userId: ID!) {
|
||||
scanUser(userId: $userId) {
|
||||
success
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ const SettingsIcon = props => {
|
|||
}
|
||||
|
||||
const ALBUM_PATH_QUERY = gql`
|
||||
query albumPathQuery($id: Int!) {
|
||||
query albumPathQuery($id: ID!) {
|
||||
album(id: $id) {
|
||||
id
|
||||
path {
|
||||
|
|
|
@ -7,7 +7,7 @@ import { Icon } from 'semantic-ui-react'
|
|||
import { ProtectedImage } from './ProtectedMedia'
|
||||
|
||||
const markFavoriteMutation = gql`
|
||||
mutation markMediaFavorite($mediaId: Int!, $favorite: Boolean!) {
|
||||
mutation markMediaFavorite($mediaId: ID!, $favorite: Boolean!) {
|
||||
favoriteMedia(mediaId: $mediaId, favorite: $favorite) {
|
||||
id
|
||||
favorite
|
||||
|
|
|
@ -4,7 +4,7 @@ import { useQuery, gql } from '@apollo/client'
|
|||
import SidebarShare from './Sharing'
|
||||
|
||||
const albumQuery = gql`
|
||||
query getAlbumSidebar($id: Int!) {
|
||||
query getAlbumSidebar($id: ID!) {
|
||||
album(id: $id) {
|
||||
id
|
||||
title
|
||||
|
|
|
@ -9,7 +9,7 @@ import SidebarDownload from './SidebarDownload'
|
|||
import SidebarItem from './SidebarItem'
|
||||
|
||||
const mediaQuery = gql`
|
||||
query sidebarPhoto($id: Int!) {
|
||||
query sidebarPhoto($id: ID!) {
|
||||
media(id: $id) {
|
||||
id
|
||||
title
|
||||
|
|
|
@ -13,7 +13,7 @@ import copy from 'copy-to-clipboard'
|
|||
import { authToken } from '../../authentication'
|
||||
|
||||
const sharePhotoQuery = gql`
|
||||
query sidbarGetPhotoShares($id: Int!) {
|
||||
query sidbarGetPhotoShares($id: ID!) {
|
||||
media(id: $id) {
|
||||
id
|
||||
shares {
|
||||
|
@ -25,7 +25,7 @@ const sharePhotoQuery = gql`
|
|||
`
|
||||
|
||||
const shareAlbumQuery = gql`
|
||||
query sidbarGetAlbumShares($id: Int!) {
|
||||
query sidbarGetAlbumShares($id: ID!) {
|
||||
album(id: $id) {
|
||||
id
|
||||
shares {
|
||||
|
@ -37,7 +37,7 @@ const shareAlbumQuery = gql`
|
|||
`
|
||||
|
||||
const addPhotoShareMutation = gql`
|
||||
mutation sidebarPhotoAddShare($id: Int!, $password: String, $expire: Time) {
|
||||
mutation sidebarPhotoAddShare($id: ID!, $password: String, $expire: Time) {
|
||||
shareMedia(mediaId: $id, password: $password, expire: $expire) {
|
||||
token
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ const addPhotoShareMutation = gql`
|
|||
`
|
||||
|
||||
const addAlbumShareMutation = gql`
|
||||
mutation sidebarAlbumAddShare($id: Int!, $password: String, $expire: Time) {
|
||||
mutation sidebarAlbumAddShare($id: ID!, $password: String, $expire: Time) {
|
||||
shareAlbum(albumId: $id, password: $password, expire: $expire) {
|
||||
token
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import { useLazyQuery, gql } from '@apollo/client'
|
|||
import { authToken } from '../../authentication'
|
||||
|
||||
export const SIDEBAR_DOWNLOAD_QUERY = gql`
|
||||
query sidebarDownloadQuery($mediaId: Int!) {
|
||||
query sidebarDownloadQuery($mediaId: ID!) {
|
||||
media(id: $mediaId) {
|
||||
id
|
||||
downloads {
|
||||
|
|
Loading…
Reference in New Issue