fix: media asset on local proxy server

This commit is contained in:
Daniel Lautzenheiser 2023-01-10 16:00:07 -05:00
parent 0678b3ead8
commit 81930a7010
27 changed files with 141 additions and 19 deletions

View File

@ -0,0 +1,3 @@
authors:
- name: George
description: A person I know

View File

@ -0,0 +1,9 @@
{
"front_limit": 5,
"site_title": "Test",
"posts": {
"front_limit": 4,
"author": "Bob",
"thumb": "/backends/proxy/assets/upload/kanefreeman_2.jpg"
}
}

View File

@ -0,0 +1,5 @@
---
title: A Question
posts:
---
Here's the body!

View File

@ -0,0 +1,11 @@
---
title: Something something something...
draft: false
date: 2022-11-01 06:30
image: /backends/proxy/assets/posts/ori_3587884_d966kldqzc6mvdeq67hyk16rnbe3gb1k8eeoy31s_shark-icon.jpg
---
# Welcome
Here is your body!
And some more information!

View File

@ -0,0 +1,13 @@
---
title: Test
draft: false
date: 2022-11-01 14:28
image: /backends/proxy/assets/posts/kittens.jpg
---
Test2
<br>
![moby-dick.jpg](/assets/upload/moby-dick.jpg)
![moby-dick.jpg](/assets/upload/moby-dick.jpg)
![kanefreeman_2.jpg](/assets/upload/kanefreeman_2.jpg)

View File

@ -0,0 +1,7 @@
---
title: Test3
draft: false
date: 2022-11-02 08:43
image: /backends/proxy/assets/upload/kanefreeman_2.jpg
---
test25555

View File

@ -0,0 +1,57 @@
---
post: Something something something...
title: Test
boolean: false
map: '{"type":"Point","coordinates":[-86.9531232,40.4469471]}'
text: test
number: 5
markdown: test
datetime: 2022-11-09T12:43:36.323-05:00
color: "#923a3a"
colorEditable: "#833a3a"
image: /backends/proxy/assets/upload/moby-dick.jpg
file: /backends/proxy/assets/upload/kanefreeman_widescreen.png
select: a
select_multiple:
- a
- b
select_numeric: 1
object:
boolean: true
datetime: 2022-11-09T12:43:36.356-05:00
post: Test
string: test
text: test
number: 3
markdown: Ttest
image: /backends/proxy/assets/upload/moby-dick.jpg
file: /backends/proxy/assets/upload/static-cms-logo.png
select: a
list:
- object:
list:
hidden: hidden
boolean: false
datetime: 2022-11-09T12:44:36.654-05:00
string: test
text: test
number: 5
markdown: test
image: /backends/proxy/assets/upload/static-cms-logo.png
file: /backends/proxy/assets/upload/kanefreeman_widescreen.png
select: b
boolean: false
datetime: 2022-11-09T12:44:36.643-05:00
string: test
text: test
number: 5
markdown: test
image: /backends/proxy/assets/upload/kanefreeman_2.jpg
file: /backends/proxy/assets/upload/static-cms-logo.png
select: a
typed_list:
- type: type_1_object
boolean: false
string: test
text: test
---

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 330 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 330 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

View File

@ -5,18 +5,18 @@ backend:
local_backend: true local_backend: true
media_folder: assets/upload media_folder: /packages/core/dev-test/backends/proxy/assets/upload
public_folder: /assets/upload public_folder: /backends/proxy/assets/upload
collections: collections:
- name: posts - name: posts
label: Posts label: Posts
label_singular: Post label_singular: Post
media_folder: /assets/posts media_folder: /packages/core/dev-test/backends/proxy/assets/posts
public_folder: /assets/posts public_folder: /backends/proxy/assets/posts
description: > description: >
The description is a great place for tone setting, high level information, The description is a great place for tone setting, high level information,
and editing guidelines that are specific to a collection. and editing guidelines that are specific to a collection.
folder: _posts folder: packages/core/dev-test/backends/proxy/_posts
slug: '{{year}}-{{month}}-{{day}}-{{slug}}' slug: '{{year}}-{{month}}-{{day}}-{{slug}}'
summary: '{{title}} -- {{year}}/{{month}}/{{day}}' summary: '{{title}} -- {{year}}/{{month}}/{{day}}'
sortable_fields: sortable_fields:
@ -66,7 +66,7 @@ collections:
hint: Main content goes here. hint: Main content goes here.
- name: faq - name: faq
label: FAQ label: FAQ
folder: _faqs folder: packages/core/dev-test/backends/proxy/_faqs
create: true create: true
fields: fields:
- label: Question - label: Question
@ -98,7 +98,7 @@ collections:
files: files:
- name: general - name: general
label: Site Settings label: Site Settings
file: _data/settings.json file: packages/core/dev-test/backends/proxy/_data/settings.json
description: General Site Settings description: General Site Settings
fields: fields:
- label: Number of posts on frontpage - label: Number of posts on frontpage
@ -127,7 +127,7 @@ collections:
required: false required: false
- name: authors - name: authors
label: Authors label: Authors
file: _data/authors.yml file: packages/core/dev-test/backends/proxy/_data/authors.yml
description: Author descriptions description: Author descriptions
fields: fields:
- name: authors - name: authors
@ -144,7 +144,7 @@ collections:
widget: text widget: text
- name: kitchenSink - name: kitchenSink
label: Kitchen Sink label: Kitchen Sink
folder: _sink folder: packages/core/dev-test/backends/proxy/_sink
create: true create: true
fields: fields:
- label: Related Post - label: Related Post

View File

@ -38,7 +38,7 @@ import {
selectInferedField, selectInferedField,
selectMediaFolders, selectMediaFolders,
} from './lib/util/collection.util'; } from './lib/util/collection.util';
import { selectMediaFilePath } from './lib/util/media.util'; import { selectMediaFilePath, selectMediaFilePublicPath } from './lib/util/media.util';
import { set } from './lib/util/object.util'; import { set } from './lib/util/object.util';
import { dateParsers, expandPath, extractTemplateVars } from './lib/widgets/stringTemplate'; import { dateParsers, expandPath, extractTemplateVars } from './lib/widgets/stringTemplate';
import createEntry from './valueObjects/createEntry'; import createEntry from './valueObjects/createEntry';
@ -786,7 +786,16 @@ export class Backend<BC extends BackendClass = BackendClass> {
const mediaFolders = selectMediaFolders(configState.config, collection, entry); const mediaFolders = selectMediaFolders(configState.config, collection, entry);
if (mediaFolders.length > 0) { if (mediaFolders.length > 0) {
const files = await Promise.all( const files = await Promise.all(
mediaFolders.map(folder => this.implementation.getMedia(folder)), mediaFolders.map(folder => {
const mediaPath = selectMediaFilePublicPath(
configState.config!,
collection,
'',
entry,
undefined,
);
return this.implementation.getMedia(folder, mediaPath);
}),
); );
entry.mediaFiles = entry.mediaFiles.concat(...files); entry.mediaFiles = entry.mediaFiles.concat(...files);
} else { } else {

View File

@ -48,6 +48,7 @@ function deserializeMediaFile({ id, content, encoding, path, name }: MediaFile)
export default class ProxyBackend implements BackendClass { export default class ProxyBackend implements BackendClass {
proxyUrl: string; proxyUrl: string;
mediaFolder?: string; mediaFolder?: string;
publicFolder?: string;
options: {}; options: {};
branch: string; branch: string;
@ -59,6 +60,7 @@ export default class ProxyBackend implements BackendClass {
this.branch = config.backend.branch || 'main'; this.branch = config.backend.branch || 'main';
this.proxyUrl = config.backend.proxy_url; this.proxyUrl = config.backend.proxy_url;
this.mediaFolder = config.media_folder; this.mediaFolder = config.media_folder;
this.publicFolder = config.public_folder;
this.options = options; this.options = options;
} }
@ -144,17 +146,17 @@ export default class ProxyBackend implements BackendClass {
}); });
} }
async getMedia(mediaFolder = this.mediaFolder) { async getMedia(mediaFolder = this.mediaFolder, publicFolder = this.publicFolder) {
const files: { path: string; url: string }[] = await this.request({ const files: { path: string; url: string }[] = await this.request({
action: 'getMedia', action: 'getMedia',
params: { branch: this.branch, mediaFolder }, params: { branch: this.branch, mediaFolder, publicFolder },
}); });
return files.map(({ url, path }) => { return files.map(({ url, path }) => {
const id = url; const id = url;
const name = basename(path); const name = basename(path);
return { id, name, displayURL: { id, path }, path }; return { id, name, displayURL: { id, path: url }, path };
}); });
} }

View File

@ -73,8 +73,8 @@ const CardWrapper = ({
<div <div
style={{ style={{
...style, ...style,
left: typeof style.left === 'number' ? style.left ?? +gutter * columnIndex : style.left, left: typeof style.left === 'number' ? style.left ?? gutter * columnIndex : style.left,
top: typeof style.top === 'number' ? style.top + gutter : style.top, top: style.top,
width: typeof style.width === 'number' ? style.width - gutter : style.width, width: typeof style.width === 'number' ? style.width - gutter : style.width,
height: typeof style.height === 'number' ? style.height - gutter : style.height, height: typeof style.height === 'number' ? style.height - gutter : style.height,
}} }}
@ -156,6 +156,7 @@ const VirtualizedGrid = (props: MediaLibraryCardGridProps) => {
columnCount, columnCount,
} as CardGridItemData } as CardGridItemData
} }
style={{ overflow: 'hidden', overflowY: 'scroll' }}
> >
{CardWrapper} {CardWrapper}
</Grid> </Grid>

View File

@ -25,7 +25,7 @@ const StyledFab = styled(Fab)`
* TODO Responsive styling needs to be overhauled. Current setup requires specifying * TODO Responsive styling needs to be overhauled. Current setup requires specifying
* widths per breakpoint. * widths per breakpoint.
*/ */
const cardWidth = `280px`; const cardWidth = `278px`;
const cardHeight = `240px`; const cardHeight = `240px`;
const cardMargin = `10px`; const cardMargin = `10px`;

View File

@ -1,7 +1,12 @@
import { isEmpty } from '../lib/util/string.util';
import FileFormatter from './FileFormatter'; import FileFormatter from './FileFormatter';
class JsonFormatter extends FileFormatter { class JsonFormatter extends FileFormatter {
fromFile(content: string) { fromFile(content: string) {
if (isEmpty(content)) {
return {};
}
return JSON.parse(content); return JSON.parse(content);
} }

View File

@ -436,7 +436,7 @@ export abstract class BackendClass {
abstract entriesByFiles(files: ImplementationFile[]): Promise<ImplementationEntry[]>; abstract entriesByFiles(files: ImplementationFile[]): Promise<ImplementationEntry[]>;
abstract getMediaDisplayURL(displayURL: DisplayURL): Promise<string>; abstract getMediaDisplayURL(displayURL: DisplayURL): Promise<string>;
abstract getMedia(folder?: string): Promise<ImplementationMediaFile[]>; abstract getMedia(folder?: string, mediaPath?: string): Promise<ImplementationMediaFile[]>;
abstract getMediaFile(path: string): Promise<ImplementationMediaFile>; abstract getMediaFile(path: string): Promise<ImplementationMediaFile>;
abstract persistEntry(entry: BackendEntry, opts: PersistOptions): Promise<void>; abstract persistEntry(entry: BackendEntry, opts: PersistOptions): Promise<void>;

View File

@ -255,7 +255,7 @@ export function selectMediaFolders(config: Config, collection: Collection, entry
folders.unshift(selectMediaFolder(config, newCollection, entry, undefined)); folders.unshift(selectMediaFolder(config, newCollection, entry, undefined));
} }
return [...new Set(...folders)]; return [...new Set(folders)];
} }
export function getFieldsNames(fields: Field[] | undefined, prefix = '') { export function getFieldsNames(fields: Field[] | undefined, prefix = '') {
let names = fields?.map(f => `${prefix}${f.name}`) ?? []; let names = fields?.map(f => `${prefix}${f.name}`) ?? [];