@rubixstudios/payload-media 1.2.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -35
- package/dist/components/media-search/index.d.ts.map +1 -1
- package/dist/components/media-search/index.js +6 -5
- package/dist/components/search-drawer/filters/pexels.d.ts +4 -4
- package/dist/components/search-drawer/filters/pexels.d.ts.map +1 -1
- package/dist/components/search-drawer/filters/pexels.js +9 -8
- package/dist/components/search-drawer/filters/pixabay.d.ts +4 -4
- package/dist/components/search-drawer/filters/pixabay.d.ts.map +1 -1
- package/dist/components/search-drawer/filters/pixabay.js +11 -11
- package/dist/components/search-drawer/filters/unsplash.d.ts +4 -4
- package/dist/components/search-drawer/filters/unsplash.d.ts.map +1 -1
- package/dist/components/search-drawer/filters/unsplash.js +5 -5
- package/dist/components/search-drawer/index.d.ts +2 -2
- package/dist/components/search-drawer/index.d.ts.map +1 -1
- package/dist/components/search-drawer/index.js +56 -50
- package/dist/components/search-drawer/media/image.d.ts +2 -2
- package/dist/components/search-drawer/media/image.d.ts.map +1 -1
- package/dist/components/search-drawer/media/image.js +2 -2
- package/dist/components/search-drawer/media/video.d.ts +2 -2
- package/dist/components/search-drawer/media/video.d.ts.map +1 -1
- package/dist/components/search-drawer/media/video.js +5 -3
- package/dist/components/search-drawer/style.css +1 -1
- package/dist/endpoints/handler/Pexels.d.ts.map +1 -1
- package/dist/endpoints/handler/Pexels.js +7 -21
- package/dist/endpoints/handler/Pixabay.d.ts.map +1 -1
- package/dist/endpoints/handler/Pixabay.js +9 -22
- package/dist/endpoints/handler/Provider.d.ts +3 -3
- package/dist/endpoints/handler/Provider.d.ts.map +1 -1
- package/dist/endpoints/handler/Provider.js +11 -11
- package/dist/endpoints/handler/Unsplash.d.ts.map +1 -1
- package/dist/endpoints/handler/Unsplash.js +2 -6
- package/dist/endpoints/index.d.ts.map +1 -1
- package/dist/endpoints/index.js +42 -75
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -19
- package/dist/lib/cache.d.ts.map +1 -1
- package/dist/lib/cache.js +12 -9
- package/dist/types.d.ts +101 -100
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/fetchCache.d.ts.map +1 -1
- package/dist/utils/fetchCache.js +4 -4
- package/dist/utils/getProviders.d.ts +1 -1
- package/dist/utils/getProviders.d.ts.map +1 -1
- package/dist/utils/getProviders.js +6 -6
- package/dist/utils/resolveProvider.d.ts +1 -4
- package/dist/utils/resolveProvider.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/endpoints/index.js
CHANGED
|
@@ -2,6 +2,36 @@ import { getMediaType } from '../utils/getMediaType.js';
|
|
|
2
2
|
import { getProviders } from '../utils/getProviders.js';
|
|
3
3
|
import { requireAccess } from '../utils/requireAccess.js';
|
|
4
4
|
import { resolveProvider } from '../utils/resolveProvider.js';
|
|
5
|
+
const getProvider = (req)=>{
|
|
6
|
+
const provider = resolveProvider(req);
|
|
7
|
+
if (!provider) {
|
|
8
|
+
return Response.json({
|
|
9
|
+
data: null,
|
|
10
|
+
error: 'Provider not supported.'
|
|
11
|
+
}, {
|
|
12
|
+
status: 404
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
if (!provider.isConfigured) {
|
|
16
|
+
return Response.json({
|
|
17
|
+
data: null,
|
|
18
|
+
error: 'Provider not configured.'
|
|
19
|
+
}, {
|
|
20
|
+
status: 500
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return provider;
|
|
24
|
+
};
|
|
25
|
+
const getFilters = (query)=>({
|
|
26
|
+
category: query.category,
|
|
27
|
+
color: query.color,
|
|
28
|
+
colors: query.colors,
|
|
29
|
+
image_type: query.image_type,
|
|
30
|
+
order: query.order,
|
|
31
|
+
orientation: query.orientation,
|
|
32
|
+
size: query.size,
|
|
33
|
+
media: getMediaType(query.media)
|
|
34
|
+
});
|
|
5
35
|
export const providers = [
|
|
6
36
|
{
|
|
7
37
|
path: '/providers',
|
|
@@ -10,12 +40,12 @@ export const providers = [
|
|
|
10
40
|
const denied = await requireAccess(req);
|
|
11
41
|
if (denied) return denied;
|
|
12
42
|
const providerKeys = req.payload?.config?.custom?.providerKeys;
|
|
13
|
-
const
|
|
14
|
-
name:
|
|
15
|
-
key:
|
|
43
|
+
const data = getProviders(providerKeys).map((provider)=>({
|
|
44
|
+
name: provider.name,
|
|
45
|
+
key: provider.key
|
|
16
46
|
}));
|
|
17
47
|
return Response.json({
|
|
18
|
-
data
|
|
48
|
+
data,
|
|
19
49
|
error: null
|
|
20
50
|
});
|
|
21
51
|
}
|
|
@@ -26,33 +56,9 @@ export const providers = [
|
|
|
26
56
|
handler: async (req)=>{
|
|
27
57
|
const denied = await requireAccess(req);
|
|
28
58
|
if (denied) return denied;
|
|
29
|
-
const provider =
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
data: null,
|
|
33
|
-
error: 'Provider not supported.'
|
|
34
|
-
}, {
|
|
35
|
-
status: 404
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
if (!provider.isConfigured) {
|
|
39
|
-
return Response.json({
|
|
40
|
-
data: null,
|
|
41
|
-
error: 'Provider not configured.'
|
|
42
|
-
}, {
|
|
43
|
-
status: 500
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
const data = await provider.getFeatured({
|
|
47
|
-
category: req.query.category,
|
|
48
|
-
color: req.query.color,
|
|
49
|
-
colors: req.query.colors,
|
|
50
|
-
image_type: req.query.image_type,
|
|
51
|
-
order: req.query.order,
|
|
52
|
-
orientation: req.query.orientation,
|
|
53
|
-
size: req.query.size,
|
|
54
|
-
media: getMediaType(req.query.media)
|
|
55
|
-
});
|
|
59
|
+
const provider = getProvider(req);
|
|
60
|
+
if (provider instanceof Response) return provider;
|
|
61
|
+
const data = await provider.getFeatured(getFilters(req.query));
|
|
56
62
|
return Response.json({
|
|
57
63
|
data,
|
|
58
64
|
error: null
|
|
@@ -65,33 +71,9 @@ export const providers = [
|
|
|
65
71
|
handler: async (req)=>{
|
|
66
72
|
const denied = await requireAccess(req);
|
|
67
73
|
if (denied) return denied;
|
|
68
|
-
const provider =
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
data: null,
|
|
72
|
-
error: 'Provider not supported.'
|
|
73
|
-
}, {
|
|
74
|
-
status: 404
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
if (!provider.isConfigured) {
|
|
78
|
-
return Response.json({
|
|
79
|
-
data: null,
|
|
80
|
-
error: 'Provider not configured.'
|
|
81
|
-
}, {
|
|
82
|
-
status: 500
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
const data = await provider.getSearch(req.query.query, Number(req.query.page ?? 1), {
|
|
86
|
-
category: req.query.category,
|
|
87
|
-
color: req.query.color,
|
|
88
|
-
colors: req.query.colors,
|
|
89
|
-
image_type: req.query.image_type,
|
|
90
|
-
order: req.query.order,
|
|
91
|
-
orientation: req.query.orientation,
|
|
92
|
-
size: req.query.size,
|
|
93
|
-
media: getMediaType(req.query.media)
|
|
94
|
-
});
|
|
74
|
+
const provider = getProvider(req);
|
|
75
|
+
if (provider instanceof Response) return provider;
|
|
76
|
+
const data = await provider.getSearch(req.query.query, Number(req.query.page ?? 1), getFilters(req.query));
|
|
95
77
|
return Response.json({
|
|
96
78
|
data,
|
|
97
79
|
error: null
|
|
@@ -104,23 +86,8 @@ export const providers = [
|
|
|
104
86
|
handler: async (req)=>{
|
|
105
87
|
const denied = await requireAccess(req);
|
|
106
88
|
if (denied) return denied;
|
|
107
|
-
const provider =
|
|
108
|
-
if (
|
|
109
|
-
return Response.json({
|
|
110
|
-
data: null,
|
|
111
|
-
error: 'Provider not supported.'
|
|
112
|
-
}, {
|
|
113
|
-
status: 404
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
if (!provider.isConfigured) {
|
|
117
|
-
return Response.json({
|
|
118
|
-
data: null,
|
|
119
|
-
error: 'Provider not configured.'
|
|
120
|
-
}, {
|
|
121
|
-
status: 500
|
|
122
|
-
});
|
|
123
|
-
}
|
|
89
|
+
const provider = getProvider(req);
|
|
90
|
+
if (provider instanceof Response) return provider;
|
|
124
91
|
const data = provider.trackDownload(req.query.url);
|
|
125
92
|
return Response.json({
|
|
126
93
|
data,
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrC,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD,eAAO,MAAM,WAAW,kBACP,cAAc,sBACZ,MAAM,KAAG,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrC,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD,eAAO,MAAM,WAAW,kBACP,cAAc,sBACZ,MAAM,KAAG,MA+CzB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -2,47 +2,46 @@ import { defaultPluginOptions } from './defaults.js';
|
|
|
2
2
|
import { providers } from './endpoints/index.js';
|
|
3
3
|
export const mediaPlugin = (pluginConfig = {})=>(incomingConfig)=>{
|
|
4
4
|
if (pluginConfig.disabled) return incomingConfig;
|
|
5
|
-
const
|
|
5
|
+
const options = {
|
|
6
6
|
...defaultPluginOptions,
|
|
7
7
|
...pluginConfig
|
|
8
8
|
};
|
|
9
|
-
const
|
|
9
|
+
const config = {
|
|
10
10
|
...incomingConfig
|
|
11
11
|
};
|
|
12
|
-
|
|
13
|
-
...
|
|
14
|
-
providerAccess:
|
|
12
|
+
config.custom = {
|
|
13
|
+
...config.custom ?? {},
|
|
14
|
+
providerAccess: options.access,
|
|
15
15
|
providerKeys: {
|
|
16
|
-
pexels:
|
|
17
|
-
unsplash:
|
|
18
|
-
pixabay:
|
|
16
|
+
pexels: options.pexels,
|
|
17
|
+
unsplash: options.unsplash,
|
|
18
|
+
pixabay: options.pixabay
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
|
-
|
|
21
|
+
config.collections = (config.collections ?? []).map((collection)=>{
|
|
22
22
|
const upload = collection.upload;
|
|
23
23
|
if (!upload) return collection;
|
|
24
|
-
const
|
|
25
|
-
|
|
24
|
+
const uploadConfig = upload === true ? {} : typeof upload === 'object' ? upload : undefined;
|
|
25
|
+
return {
|
|
26
26
|
...collection,
|
|
27
27
|
upload: {
|
|
28
|
-
...
|
|
28
|
+
...uploadConfig ?? {},
|
|
29
29
|
admin: {
|
|
30
|
-
...
|
|
30
|
+
...uploadConfig?.admin ?? {},
|
|
31
31
|
components: {
|
|
32
|
-
...
|
|
32
|
+
...uploadConfig?.admin?.components ?? {},
|
|
33
33
|
controls: [
|
|
34
|
-
...
|
|
34
|
+
...uploadConfig?.admin?.components?.controls ?? [],
|
|
35
35
|
'@rubixstudios/payload-media/client#MediaSearch'
|
|
36
36
|
]
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
|
-
return modifiedCollection;
|
|
42
41
|
});
|
|
43
|
-
|
|
44
|
-
...
|
|
42
|
+
config.endpoints = [
|
|
43
|
+
...config.endpoints ?? [],
|
|
45
44
|
...providers
|
|
46
45
|
];
|
|
47
|
-
return
|
|
46
|
+
return config;
|
|
48
47
|
};
|
package/dist/lib/cache.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/lib/cache.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/lib/cache.ts"],"names":[],"mappings":"AAOA,qBAAa,YAAY;IACvB,OAAO,CAAC,eAAe;IAIvB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAI7B;IAED,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAwB1B;IAED,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAUpD;CACF"}
|
package/dist/lib/cache.js
CHANGED
|
@@ -9,20 +9,23 @@ export class CacheManager {
|
|
|
9
9
|
}
|
|
10
10
|
get(query) {
|
|
11
11
|
const key = this.getVersionedKey(query);
|
|
12
|
-
const
|
|
13
|
-
if (!
|
|
14
|
-
let item;
|
|
12
|
+
const stored = localStorage.getItem(key);
|
|
13
|
+
if (!stored) return null;
|
|
15
14
|
try {
|
|
16
|
-
item = JSON.parse(
|
|
15
|
+
const item = JSON.parse(stored);
|
|
16
|
+
if (!item || typeof item !== 'object' || !('value' in item)) {
|
|
17
|
+
localStorage.removeItem(key);
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
if (item.expiry && Date.now() > item.expiry) {
|
|
21
|
+
localStorage.removeItem(key);
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return item.value;
|
|
17
25
|
} catch {
|
|
18
26
|
localStorage.removeItem(key);
|
|
19
27
|
return null;
|
|
20
28
|
}
|
|
21
|
-
if (item.expiry && Date.now() > item.expiry) {
|
|
22
|
-
localStorage.removeItem(key);
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
return item.value;
|
|
26
29
|
}
|
|
27
30
|
set(query, data, ttl) {
|
|
28
31
|
const key = this.getVersionedKey(query);
|
package/dist/types.d.ts
CHANGED
|
@@ -1,39 +1,68 @@
|
|
|
1
1
|
import { type Access } from 'payload';
|
|
2
|
+
export type MediaType = 'image' | 'video';
|
|
2
3
|
export type MediaOption = {
|
|
3
4
|
label: string;
|
|
4
|
-
value:
|
|
5
|
+
value: MediaType;
|
|
5
6
|
};
|
|
6
7
|
export declare const MediaOptions: MediaOption[];
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
export type ProviderConfig = {
|
|
9
|
+
access?: Access;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
openverse?: string;
|
|
12
|
+
pexels?: string;
|
|
13
|
+
pixabay?: string;
|
|
14
|
+
unsplash?: string;
|
|
15
|
+
};
|
|
16
|
+
export type ProviderKeys = {
|
|
17
|
+
unsplash?: string;
|
|
18
|
+
openverse?: string;
|
|
19
|
+
pexels?: string;
|
|
20
|
+
pixabay?: string;
|
|
21
|
+
};
|
|
22
|
+
type ProviderKey = 'unsplash' | 'pexels' | 'pixabay';
|
|
23
|
+
export type ProviderOption = {
|
|
24
|
+
label: string;
|
|
25
|
+
value: ProviderKey;
|
|
26
|
+
};
|
|
27
|
+
export type ProviderFilters = {
|
|
28
|
+
provider: 'unsplash';
|
|
29
|
+
options: UnsplashFilters;
|
|
30
|
+
} | {
|
|
31
|
+
provider: 'pexels';
|
|
32
|
+
options: PexelsFilters;
|
|
33
|
+
} | {
|
|
34
|
+
provider: 'pixabay';
|
|
35
|
+
options: PixabayFilters;
|
|
36
|
+
};
|
|
37
|
+
export interface ProviderResult {
|
|
38
|
+
alt: string;
|
|
39
|
+
attribution: {
|
|
40
|
+
name: string;
|
|
41
|
+
link: string;
|
|
42
|
+
};
|
|
43
|
+
avatar?: string;
|
|
44
|
+
color: string;
|
|
19
45
|
height: number;
|
|
20
46
|
id: string;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
47
|
+
likes?: number;
|
|
48
|
+
urls: {
|
|
49
|
+
view: string;
|
|
50
|
+
original: string;
|
|
51
|
+
download: string;
|
|
52
|
+
downloadLocation?: string;
|
|
53
|
+
};
|
|
25
54
|
width: number;
|
|
26
55
|
}
|
|
27
|
-
export declare const PexelsColours: {
|
|
28
|
-
label: string;
|
|
29
|
-
value: string;
|
|
30
|
-
}[];
|
|
31
56
|
export type PexelsFilters = {
|
|
32
57
|
orientation?: string;
|
|
33
58
|
size?: string;
|
|
34
|
-
media?:
|
|
59
|
+
media?: MediaType;
|
|
35
60
|
color?: string;
|
|
36
61
|
};
|
|
62
|
+
export declare const PexelsColours: {
|
|
63
|
+
label: string;
|
|
64
|
+
value: string;
|
|
65
|
+
}[];
|
|
37
66
|
export declare const PexelsOrientation: {
|
|
38
67
|
label: string;
|
|
39
68
|
value: string;
|
|
@@ -42,6 +71,24 @@ export declare const PexelsSize: {
|
|
|
42
71
|
label: string;
|
|
43
72
|
value: string;
|
|
44
73
|
}[];
|
|
74
|
+
export declare const PexelsVideoSize: {
|
|
75
|
+
label: string;
|
|
76
|
+
value: string;
|
|
77
|
+
}[];
|
|
78
|
+
export interface PexelsResult {
|
|
79
|
+
alt: string;
|
|
80
|
+
avg_color: string;
|
|
81
|
+
height: number;
|
|
82
|
+
id: string;
|
|
83
|
+
photographer: string;
|
|
84
|
+
photographer_url: string;
|
|
85
|
+
src: {
|
|
86
|
+
medium: string;
|
|
87
|
+
original: string;
|
|
88
|
+
};
|
|
89
|
+
url: string;
|
|
90
|
+
width: number;
|
|
91
|
+
}
|
|
45
92
|
interface PexelsVideoUser {
|
|
46
93
|
id: number;
|
|
47
94
|
name: string;
|
|
@@ -79,24 +126,14 @@ export interface PexelsVideoResponse {
|
|
|
79
126
|
url: string;
|
|
80
127
|
videos: PexelsVideo[];
|
|
81
128
|
}
|
|
82
|
-
export
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
id: string;
|
|
91
|
-
photographer: string;
|
|
92
|
-
photographer_url: string;
|
|
93
|
-
src: {
|
|
94
|
-
medium: string;
|
|
95
|
-
original: string;
|
|
96
|
-
};
|
|
97
|
-
url: string;
|
|
98
|
-
width: number;
|
|
99
|
-
}
|
|
129
|
+
export type PixabayFilters = {
|
|
130
|
+
image_type?: string;
|
|
131
|
+
orientation?: string;
|
|
132
|
+
category?: string;
|
|
133
|
+
colors?: string;
|
|
134
|
+
order?: string;
|
|
135
|
+
media?: MediaType;
|
|
136
|
+
};
|
|
100
137
|
export declare const PixabayCategories: {
|
|
101
138
|
label: string;
|
|
102
139
|
value: string;
|
|
@@ -105,14 +142,6 @@ export declare const PixabayColours: {
|
|
|
105
142
|
label: string;
|
|
106
143
|
value: string;
|
|
107
144
|
}[];
|
|
108
|
-
export type PixabayFilters = {
|
|
109
|
-
image_type?: string;
|
|
110
|
-
orientation?: string;
|
|
111
|
-
category?: string;
|
|
112
|
-
colors?: string;
|
|
113
|
-
order?: string;
|
|
114
|
-
media?: 'image' | 'video';
|
|
115
|
-
};
|
|
116
145
|
export declare const PixabayImageType: {
|
|
117
146
|
label: string;
|
|
118
147
|
value: string;
|
|
@@ -170,63 +199,15 @@ export interface PixabayVideoResponse {
|
|
|
170
199
|
total: number;
|
|
171
200
|
totalHits: number;
|
|
172
201
|
}
|
|
173
|
-
export type
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
pexels?: string;
|
|
178
|
-
pixabay?: string;
|
|
179
|
-
unsplash?: string;
|
|
180
|
-
};
|
|
181
|
-
export type ProviderFilters = {
|
|
182
|
-
provider: 'unsplash';
|
|
183
|
-
options: UnsplashFilters;
|
|
184
|
-
} | {
|
|
185
|
-
provider: 'pexels';
|
|
186
|
-
options: PexelsFilters;
|
|
187
|
-
} | {
|
|
188
|
-
provider: 'pixabay';
|
|
189
|
-
options: PixabayFilters;
|
|
190
|
-
};
|
|
191
|
-
export type ProviderKeys = {
|
|
192
|
-
unsplash?: string;
|
|
193
|
-
openverse?: string;
|
|
194
|
-
pexels?: string;
|
|
195
|
-
pixabay?: string;
|
|
196
|
-
};
|
|
197
|
-
type ProviderKey = 'unsplash' | 'pexels' | 'pixabay';
|
|
198
|
-
export type ProviderOption = {
|
|
199
|
-
label: string;
|
|
200
|
-
value: ProviderKey;
|
|
202
|
+
export type UnsplashFilters = {
|
|
203
|
+
color?: string;
|
|
204
|
+
orientation?: string;
|
|
205
|
+
media?: MediaType;
|
|
201
206
|
};
|
|
202
|
-
export interface ProviderResult {
|
|
203
|
-
alt: string;
|
|
204
|
-
attribution: {
|
|
205
|
-
name: string;
|
|
206
|
-
link: string;
|
|
207
|
-
};
|
|
208
|
-
avatar?: string;
|
|
209
|
-
color: string;
|
|
210
|
-
height: number;
|
|
211
|
-
id: string;
|
|
212
|
-
likes?: number;
|
|
213
|
-
urls: {
|
|
214
|
-
view: string;
|
|
215
|
-
original: string;
|
|
216
|
-
download: string;
|
|
217
|
-
downloadLocation?: string;
|
|
218
|
-
};
|
|
219
|
-
width: number;
|
|
220
|
-
}
|
|
221
207
|
export declare const UnsplashColours: {
|
|
222
208
|
label: string;
|
|
223
209
|
value: string;
|
|
224
210
|
}[];
|
|
225
|
-
export type UnsplashFilters = {
|
|
226
|
-
color?: string;
|
|
227
|
-
orientation?: string;
|
|
228
|
-
media?: 'image' | 'video';
|
|
229
|
-
};
|
|
230
211
|
export declare const UnsplashOrientation: {
|
|
231
212
|
label: string;
|
|
232
213
|
value: string;
|
|
@@ -258,5 +239,25 @@ export interface UnsplashResult {
|
|
|
258
239
|
};
|
|
259
240
|
width: number;
|
|
260
241
|
}
|
|
242
|
+
export interface OpenverseResult {
|
|
243
|
+
background_color?: string | null;
|
|
244
|
+
creator: string | null;
|
|
245
|
+
creator_url: string | null;
|
|
246
|
+
foreign_landing_url: string | null;
|
|
247
|
+
height: number;
|
|
248
|
+
id: string;
|
|
249
|
+
source: string;
|
|
250
|
+
thumbnail: string;
|
|
251
|
+
title: string | null;
|
|
252
|
+
url: string;
|
|
253
|
+
width: number;
|
|
254
|
+
}
|
|
255
|
+
export interface OpenverseResponse {
|
|
256
|
+
page: number;
|
|
257
|
+
page_count: number;
|
|
258
|
+
page_size: number;
|
|
259
|
+
result_count: number;
|
|
260
|
+
results: OpenverseResult[];
|
|
261
|
+
}
|
|
261
262
|
export {};
|
|
262
263
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,OAAO,CAAA;AAEzC,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,SAAS,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,WAAW,EAGrC,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,KAAK,WAAW,GAAG,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAA;AAEpD,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,WAAW,CAAA;CACnB,CAAA;AA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AAA;CACd;AAED,MAAM,WAAW,eAAe;IAC9B,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAChC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAA;IAClC,MAAM,EAAE,MAAM,CAAA;IACd,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,EAAE,MAAM,CAAA;IACpB,OAAO,EAAE,eAAe,EAAE,CAAA;CAC3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchCache.d.ts","sourceRoot":"","sources":["../../src/utils/fetchCache.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,UAAU,cAAqB,MAAM,
|
|
1
|
+
{"version":3,"file":"fetchCache.d.ts","sourceRoot":"","sources":["../../src/utils/fetchCache.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,UAAU,cAAqB,MAAM,iBAuBjD,CAAA"}
|
package/dist/utils/fetchCache.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CacheManager } from '../lib/cache.js';
|
|
2
2
|
const cache = new CacheManager();
|
|
3
|
-
const
|
|
3
|
+
const CACHE_TTL = 24 * 60 * 60 * 1000;
|
|
4
4
|
export const fetchCache = async (queryPath)=>{
|
|
5
5
|
if (queryPath.includes('undefined')) {
|
|
6
6
|
throw new Error('Invalid provider');
|
|
@@ -14,7 +14,7 @@ export const fetchCache = async (queryPath)=>{
|
|
|
14
14
|
if (!response.ok) {
|
|
15
15
|
throw await response.json();
|
|
16
16
|
}
|
|
17
|
-
const
|
|
18
|
-
cache.set(key,
|
|
19
|
-
return
|
|
17
|
+
const data = await response.json();
|
|
18
|
+
cache.set(key, data, CACHE_TTL);
|
|
19
|
+
return data;
|
|
20
20
|
};
|
|
@@ -2,5 +2,5 @@ import { Pexels } from '../endpoints/handler/Pexels.js';
|
|
|
2
2
|
import { Pixabay } from '../endpoints/handler/Pixabay.js';
|
|
3
3
|
import { Unsplash } from '../endpoints/handler/Unsplash.js';
|
|
4
4
|
import { type ProviderKeys } from '../types.js';
|
|
5
|
-
export declare
|
|
5
|
+
export declare const getProviders: (providerKeys?: ProviderKeys) => (Pexels | Pixabay | Unsplash)[];
|
|
6
6
|
//# sourceMappingURL=getProviders.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getProviders.d.ts","sourceRoot":"","sources":["../../src/utils/getProviders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAA;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAA;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAA;AAC3D,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,
|
|
1
|
+
{"version":3,"file":"getProviders.d.ts","sourceRoot":"","sources":["../../src/utils/getProviders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAA;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAA;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAA;AAC3D,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,eAAO,MAAM,YAAY,kBAAmB,YAAY,oCAMvD,CAAA"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Pexels } from '../endpoints/handler/Pexels.js';
|
|
2
2
|
import { Pixabay } from '../endpoints/handler/Pixabay.js';
|
|
3
3
|
import { Unsplash } from '../endpoints/handler/Unsplash.js';
|
|
4
|
-
export
|
|
4
|
+
export const getProviders = (providerKeys)=>{
|
|
5
5
|
return [
|
|
6
|
-
new Unsplash(()=>
|
|
7
|
-
new Pexels(()=>
|
|
8
|
-
new Pixabay(()=>
|
|
9
|
-
].filter((
|
|
10
|
-
}
|
|
6
|
+
new Unsplash(()=>providerKeys?.unsplash),
|
|
7
|
+
new Pexels(()=>providerKeys?.pexels),
|
|
8
|
+
new Pixabay(()=>providerKeys?.pixabay)
|
|
9
|
+
].filter((provider)=>provider.isConfigured);
|
|
10
|
+
};
|
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
import { type PayloadRequest } from 'payload';
|
|
2
|
-
|
|
3
|
-
import { type Pixabay } from '../endpoints/handler/Pixabay.js';
|
|
4
|
-
import { type Unsplash } from '../endpoints/handler/Unsplash.js';
|
|
5
|
-
export declare const resolveProvider: (req: PayloadRequest) => Unsplash | Pexels | Pixabay | null;
|
|
2
|
+
export declare const resolveProvider: (req: PayloadRequest) => import("../endpoints/handler/Pexels.js").Pexels | import("../endpoints/handler/Pixabay.js").Pixabay | import("../endpoints/handler/Unsplash.js").Unsplash | null;
|
|
6
3
|
//# sourceMappingURL=resolveProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveProvider.d.ts","sourceRoot":"","sources":["../../src/utils/resolveProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"resolveProvider.d.ts","sourceRoot":"","sources":["../../src/utils/resolveProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAA;AAI7C,eAAO,MAAM,eAAe,QAAS,cAAc,qKAIlD,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rubixstudios/payload-media",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A Payload CMS plugin that integrates with stock image and video providers including Unsplash, Pexels and Pixabay.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Rubix Studios <hello@rubixstudios.com.au> (https://rubixstudios.com.au)",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@biomejs/biome": "2.5.15",
|
|
64
|
-
"@payloadcms/ui": "
|
|
64
|
+
"@payloadcms/ui": "4.0.0-beta.0",
|
|
65
65
|
"@semantic-release/changelog": "^7.0.0",
|
|
66
66
|
"@semantic-release/git": "^11.0.1",
|
|
67
67
|
"@swc/cli": "^0.8.1",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"typescript": "7.0.2"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
|
-
"payload": "
|
|
78
|
+
"payload": "4.0.0-beta.0"
|
|
79
79
|
},
|
|
80
80
|
"engines": {
|
|
81
81
|
"node": ">=24",
|