Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get original files #166

Merged
merged 3 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions gallery.config-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ sources:
# Offline sources require an index file. Previews and meta data
# should be extracted first before marking a source offline
#offline: false
# Allows the original files to be downloaded via de webapp.
# This adds a link to images of this source in the details view.
# Sources set as `offline` won't be made available.
#downloadable: true
# Filename matcher for checksum recalculation
# size-ctime-inode: this matcher should be used if possible, might
# not work on windows
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/config/expand-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const expandConfigDefaults = (config, env) => {
config.sources[i] = Object.assign({
index: '{configDir}/{configPrefix}{basename(dir)}.idx',
offline: false,
downloadable: false,
excludeIfPresent: '.galleryignore'
}, source)
}
Expand Down
21 changes: 21 additions & 0 deletions packages/server/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ export function createApp(context) {
router.use(getAuthMiddleware(config))

router.use('/files', express.static(config.storage.dir, {index: false, maxAge: '2d', immutable: true}));
for (const source of config.sources) {
if (!source.downloadable || source.offline) {
// If the source can't be downloaded or is offline we skip it
continue;
}
const basename = path.basename(source.index);
const idx = basename.replace(/\.[^.]+$/, '');
router.use('/sources/' + idx, express.static(source.dir, {index: false, maxAge: '2d', immutable: true, fallthrough: true}));
}

const pluginApi = browserPlugin(context, '/plugins/')
router.use('/plugins', pluginApi.static)
Expand Down Expand Up @@ -104,12 +113,24 @@ export function createApp(context) {
const disabled = config?.webapp?.disabled || []
const plugins = pluginApi.pluginEntries
const entries = await getFirstEntries(50, req)
const sources = config.sources.map((value) => {
// Don't return sources which we don't want to make downloadable
// (this is mainly to not make the index name available in the UI)
if (!value.downloadable || value.offline) {
return null;
}
return {
downloadable: true,
index: path.basename(value.index).replace(/\.[^.]+$/, '')
}
});
return {
disabled: !!req.username ? [...disabled, 'pwa'] : disabled,
pluginManager: {
plugins
},
entries,
sources,
}
}

Expand Down
23 changes: 18 additions & 5 deletions packages/webapp/src/single/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,15 @@ export const Details = ({entry, dispatch}) => {
]
}

const mainFilename = entry.files[0].filename.replace(/.*[/\\]/g, '')
const mainFileData = entry.files[0];
const mainFilename = mainFileData.filename.replace(/.*[/\\]/g, '')
const sourceConfig = appConfig.sources.find((value) => value && value.index === mainFileData.index);
const sourceLink = (text, withIcon = false) => {
if (!sourceConfig || sourceConfig.downloadable === false) return text;
return <a href={`sources/${mainFileData.index}/${mainFileData.filename}`} target="_blank">
{text} {withIcon ? <FontAwesomeIcon icon={icons.faArrowUpRightFromSquare} className="text-gray-300"/> : ''}
</a>
};

const hasAddress = entry => entry.road || entry.city || entry.country

Expand Down Expand Up @@ -136,11 +144,16 @@ export const Details = ({entry, dispatch}) => {
<FontAwesomeIcon icon={icons.faIdCard} className="text-gray-300"/>
</div>
<div>
<p>{mainFilename}</p>
<p>
{sourceLink(mainFilename)}
</p>
<p>{simpleSearchLink(entry.type, 'type', entry.type)} {entry.id.substring(0, 7)}</p>
<p>{entry.duration > 0 && (
<>{humanizeDuration(entry.duration)}, </>
)}{entry.width}x{entry.height}</p>
<p>
{entry.duration > 0 && (
<>{humanizeDuration(entry.duration)}, </>
)}
{sourceLink(`${entry.width}x${entry.height}`, true)}
</p>
</div>
</div>
<div className="flex">
Expand Down
Loading