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 { 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 }) {
|
||||
app.use('/images/:id/:image', async function(req, res) {
|
||||
app.use('/images/:id/:image', async (req, res) => {
|
||||
const { id, image } = req.params
|
||||
|
||||
let user = null
|
||||
|
@ -43,36 +75,12 @@ function loadImageRoutes({ app, driver, scanner }) {
|
|||
|
||||
let imagePath = path.resolve(getImageCachePath(id, albumId), image)
|
||||
|
||||
if (!(await fs.exists(imagePath))) {
|
||||
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)
|
||||
sendImage({ imagePath, photo, res })
|
||||
})
|
||||
|
||||
// app.use('/share/:token/:image', async (req, res) => {
|
||||
// const { token } = req.params
|
||||
// })
|
||||
}
|
||||
|
||||
export default loadImageRoutes
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import React from 'react'
|
||||
import { Query } from 'react-apollo'
|
||||
import gql from 'graphql-tag'
|
||||
import SidebarShare from './Sharing'
|
||||
|
||||
const albumQuery = gql`
|
||||
query getAlbumSidebar($id: ID!) {
|
||||
|
@ -20,7 +21,14 @@ const AlbumSidebar = ({ albumId }) => {
|
|||
if (loading) return <div>Loading...</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>
|
||||
</div>
|
||||
|
|
|
@ -3,21 +3,41 @@ import { Query, Mutation } from 'react-apollo'
|
|||
import gql from 'graphql-tag'
|
||||
import { Table, Button, Icon, Dropdown } from 'semantic-ui-react'
|
||||
|
||||
const shareQuery = gql`
|
||||
query sidbarGetShares($photoId: ID!) {
|
||||
photoShares(id: $photoId) {
|
||||
const sharePhotoQuery = gql`
|
||||
query sidbarGetPhotoShares($id: ID!) {
|
||||
photoShares(id: $id) {
|
||||
token
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
const addShareMutation = gql`
|
||||
mutation sidebarAddShare(
|
||||
$photoId: ID!
|
||||
const shareAlbumQuery = gql`
|
||||
query sidbarGetAlbumShares($id: ID!) {
|
||||
albumShares(id: $id) {
|
||||
token
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
const addPhotoShareMutation = gql`
|
||||
mutation sidebarPhotoAddShare(
|
||||
$id: ID!
|
||||
$password: String
|
||||
$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
|
||||
}
|
||||
}
|
||||
|
@ -31,18 +51,28 @@ const deleteShareMutation = gql`
|
|||
}
|
||||
`
|
||||
|
||||
const SidebarShare = ({ photo }) => {
|
||||
if (!photo || !photo.id) return null
|
||||
const SidebarShare = ({ photo, album }) => {
|
||||
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 (
|
||||
<div>
|
||||
<h2>Sharing options</h2>
|
||||
<Query query={shareQuery} variables={{ photoId: photo.id }}>
|
||||
<Query query={query} variables={{ id }}>
|
||||
{({ loading, error, data, refetch }) => {
|
||||
if (loading) return <div>Loading...</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.Cell>
|
||||
<b>Public Link</b> {share.token}
|
||||
|
@ -122,7 +152,7 @@ const SidebarShare = ({ photo }) => {
|
|||
onClick={() => {
|
||||
sharePhoto({
|
||||
variables: {
|
||||
photoId: photo.id,
|
||||
id,
|
||||
},
|
||||
})
|
||||
}}
|
||||
|
|
Loading…
Reference in New Issue