Album share
This commit is contained in:
parent
7c2e0df707
commit
27765a9c96
|
@ -5,8 +5,40 @@ import config from '../config'
|
||||||
import { isRawImage, getImageCachePath } from '../scanner/utils'
|
import { isRawImage, getImageCachePath } from '../scanner/utils'
|
||||||
import { getUserFromToken, getTokenFromBearer } from '../token'
|
import { getUserFromToken, getTokenFromBearer } from '../token'
|
||||||
|
|
||||||
|
async function sendImage({ imagePath, photo, res }) {
|
||||||
|
if (!(await fs.exists(imagePath))) {
|
||||||
|
if (image == 'thumbnail.jpg') {
|
||||||
|
console.log('Thumbnail not found, generating', photo.path)
|
||||||
|
await scanner.processImage(photo.id)
|
||||||
|
|
||||||
|
if (!(await fs.exists(imagePath))) {
|
||||||
|
throw new Error('Thumbnail not found after image processing')
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.sendFile(imagePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
imagePath = photo.path
|
||||||
|
}
|
||||||
|
|
||||||
|
if (await isRawImage(imagePath)) {
|
||||||
|
console.log('RAW preview image not found, generating', imagePath)
|
||||||
|
await scanner.processImage(id)
|
||||||
|
|
||||||
|
imagePath = path.resolve(config.cachePath, 'images', id, image)
|
||||||
|
|
||||||
|
if (!(await fs.exists(imagePath))) {
|
||||||
|
throw new Error('RAW preview not found after image processing')
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.sendFile(imagePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
res.sendFile(imagePath)
|
||||||
|
}
|
||||||
|
|
||||||
function loadImageRoutes({ app, driver, scanner }) {
|
function loadImageRoutes({ app, driver, scanner }) {
|
||||||
app.use('/images/:id/:image', async function(req, res) {
|
app.use('/images/:id/:image', async (req, res) => {
|
||||||
const { id, image } = req.params
|
const { id, image } = req.params
|
||||||
|
|
||||||
let user = null
|
let user = null
|
||||||
|
@ -43,36 +75,12 @@ function loadImageRoutes({ app, driver, scanner }) {
|
||||||
|
|
||||||
let imagePath = path.resolve(getImageCachePath(id, albumId), image)
|
let imagePath = path.resolve(getImageCachePath(id, albumId), image)
|
||||||
|
|
||||||
if (!(await fs.exists(imagePath))) {
|
sendImage({ imagePath, photo, res })
|
||||||
if (image == 'thumbnail.jpg') {
|
|
||||||
console.log('Thumbnail not found, generating', photo.path)
|
|
||||||
await scanner.processImage(id)
|
|
||||||
|
|
||||||
if (!(await fs.exists(imagePath))) {
|
|
||||||
throw new Error('Thumbnail not found after image processing')
|
|
||||||
}
|
|
||||||
|
|
||||||
return res.sendFile(imagePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
imagePath = photo.path
|
|
||||||
}
|
|
||||||
|
|
||||||
if (await isRawImage(imagePath)) {
|
|
||||||
console.log('RAW preview image not found, generating', imagePath)
|
|
||||||
await scanner.processImage(id)
|
|
||||||
|
|
||||||
imagePath = path.resolve(config.cachePath, 'images', id, image)
|
|
||||||
|
|
||||||
if (!(await fs.exists(imagePath))) {
|
|
||||||
throw new Error('RAW preview not found after image processing')
|
|
||||||
}
|
|
||||||
|
|
||||||
return res.sendFile(imagePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
res.sendFile(imagePath)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// app.use('/share/:token/:image', async (req, res) => {
|
||||||
|
// const { token } = req.params
|
||||||
|
// })
|
||||||
}
|
}
|
||||||
|
|
||||||
export default loadImageRoutes
|
export default loadImageRoutes
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { Query } from 'react-apollo'
|
import { Query } from 'react-apollo'
|
||||||
import gql from 'graphql-tag'
|
import gql from 'graphql-tag'
|
||||||
|
import SidebarShare from './Sharing'
|
||||||
|
|
||||||
const albumQuery = gql`
|
const albumQuery = gql`
|
||||||
query getAlbumSidebar($id: ID!) {
|
query getAlbumSidebar($id: ID!) {
|
||||||
|
@ -20,7 +21,14 @@ const AlbumSidebar = ({ albumId }) => {
|
||||||
if (loading) return <div>Loading...</div>
|
if (loading) return <div>Loading...</div>
|
||||||
if (error) return <div>{error.message}</div>
|
if (error) return <div>{error.message}</div>
|
||||||
|
|
||||||
return <h1>{data.album.title}</h1>
|
console.log('ALBUM', data.album)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>{data.album.title}</h1>
|
||||||
|
<SidebarShare album={data.album} />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
}}
|
}}
|
||||||
</Query>
|
</Query>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -3,21 +3,41 @@ import { Query, Mutation } from 'react-apollo'
|
||||||
import gql from 'graphql-tag'
|
import gql from 'graphql-tag'
|
||||||
import { Table, Button, Icon, Dropdown } from 'semantic-ui-react'
|
import { Table, Button, Icon, Dropdown } from 'semantic-ui-react'
|
||||||
|
|
||||||
const shareQuery = gql`
|
const sharePhotoQuery = gql`
|
||||||
query sidbarGetShares($photoId: ID!) {
|
query sidbarGetPhotoShares($id: ID!) {
|
||||||
photoShares(id: $photoId) {
|
photoShares(id: $id) {
|
||||||
token
|
token
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
const addShareMutation = gql`
|
const shareAlbumQuery = gql`
|
||||||
mutation sidebarAddShare(
|
query sidbarGetAlbumShares($id: ID!) {
|
||||||
$photoId: ID!
|
albumShares(id: $id) {
|
||||||
|
token
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
const addPhotoShareMutation = gql`
|
||||||
|
mutation sidebarPhotoAddShare(
|
||||||
|
$id: ID!
|
||||||
$password: String
|
$password: String
|
||||||
$expire: _Neo4jDateInput
|
$expire: _Neo4jDateInput
|
||||||
) {
|
) {
|
||||||
sharePhoto(photoId: $photoId, password: $password, expire: $expire) {
|
sharePhoto(photoId: $id, password: $password, expire: $expire) {
|
||||||
|
token
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
const addAlbumShareMutation = gql`
|
||||||
|
mutation sidebarAlbumAddShare(
|
||||||
|
$id: ID!
|
||||||
|
$password: String
|
||||||
|
$expire: _Neo4jDateInput
|
||||||
|
) {
|
||||||
|
shareAlbum(albumId: $id, password: $password, expire: $expire) {
|
||||||
token
|
token
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,18 +51,28 @@ const deleteShareMutation = gql`
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
const SidebarShare = ({ photo }) => {
|
const SidebarShare = ({ photo, album }) => {
|
||||||
if (!photo || !photo.id) return null
|
if ((!photo || !photo.id) && (!album || !album.id)) return null
|
||||||
|
|
||||||
|
const isPhoto = !!photo
|
||||||
|
const id = isPhoto ? photo.id : album.id
|
||||||
|
|
||||||
|
const query = isPhoto ? sharePhotoQuery : shareAlbumQuery
|
||||||
|
const addShareMutation = isPhoto
|
||||||
|
? addPhotoShareMutation
|
||||||
|
: addAlbumShareMutation
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h2>Sharing options</h2>
|
<h2>Sharing options</h2>
|
||||||
<Query query={shareQuery} variables={{ photoId: photo.id }}>
|
<Query query={query} variables={{ id }}>
|
||||||
{({ loading, error, data, refetch }) => {
|
{({ loading, error, data, refetch }) => {
|
||||||
if (loading) return <div>Loading...</div>
|
if (loading) return <div>Loading...</div>
|
||||||
if (error) return <div>Error: {error}</div>
|
if (error) return <div>Error: {error}</div>
|
||||||
|
|
||||||
const rows = data.photoShares.map(share => (
|
let shares = isPhoto ? data.photoShares : data.albumShares
|
||||||
|
|
||||||
|
const rows = shares.map(share => (
|
||||||
<Table.Row key={share.token}>
|
<Table.Row key={share.token}>
|
||||||
<Table.Cell>
|
<Table.Cell>
|
||||||
<b>Public Link</b> {share.token}
|
<b>Public Link</b> {share.token}
|
||||||
|
@ -122,7 +152,7 @@ const SidebarShare = ({ photo }) => {
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
sharePhoto({
|
sharePhoto({
|
||||||
variables: {
|
variables: {
|
||||||
photoId: photo.id,
|
id,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
|
|
Loading…
Reference in New Issue