@rubixstudios/payload-images 1.0.0 → 1.0.2
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/LICENSE +22 -22
- package/dist/components/ImageSearch/index.d.ts +4 -0
- package/dist/components/ImageSearch/index.d.ts.map +1 -0
- package/dist/components/ImageSearch/index.js +31 -0
- package/dist/components/SearchImages/heart.d.ts +4 -0
- package/dist/components/SearchImages/heart.d.ts.map +1 -0
- package/dist/components/SearchImages/heart.js +12 -0
- package/dist/components/SearchImages/index.d.ts +11 -0
- package/dist/components/SearchImages/index.d.ts.map +1 -0
- package/dist/components/SearchImages/index.js +378 -0
- package/dist/components/SearchImages/style.css +1 -0
- package/dist/defaults.d.ts +3 -0
- package/dist/defaults.d.ts.map +1 -0
- package/dist/defaults.js +8 -0
- package/dist/endpoints/handler/Pexels.d.ts +12 -0
- package/dist/endpoints/handler/Pexels.d.ts.map +1 -0
- package/dist/endpoints/handler/Pexels.js +60 -0
- package/dist/endpoints/handler/Pixabay.d.ts +12 -0
- package/dist/endpoints/handler/Pixabay.d.ts.map +1 -0
- package/dist/endpoints/handler/Pixabay.js +63 -0
- package/dist/endpoints/handler/Provider.d.ts +20 -0
- package/dist/endpoints/handler/Provider.d.ts.map +1 -0
- package/dist/endpoints/handler/Provider.js +53 -0
- package/dist/endpoints/handler/Unsplash.d.ts +13 -0
- package/dist/endpoints/handler/Unsplash.d.ts.map +1 -0
- package/dist/endpoints/handler/Unsplash.js +82 -0
- package/dist/endpoints/providers.d.ts +3 -0
- package/dist/endpoints/providers.d.ts.map +1 -0
- package/dist/endpoints/providers.js +125 -0
- package/dist/exports/client.d.ts +2 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +48 -0
- package/dist/lib/cache.d.ts +7 -0
- package/dist/lib/cache.d.ts.map +1 -0
- package/dist/lib/cache.js +34 -0
- package/dist/types.d.ts +164 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +312 -0
- package/dist/utils/fetchCache.d.ts +2 -0
- package/dist/utils/fetchCache.d.ts.map +1 -0
- package/dist/utils/fetchCache.js +15 -0
- package/dist/utils/getProvider.d.ts +6 -0
- package/dist/utils/getProvider.d.ts.map +1 -0
- package/dist/utils/getProvider.js +16 -0
- package/dist/utils/getProviders.d.ts +6 -0
- package/dist/utils/getProviders.d.ts.map +1 -0
- package/dist/utils/getProviders.js +10 -0
- package/dist/utils/requireAccess.d.ts +3 -0
- package/dist/utils/requireAccess.d.ts.map +1 -0
- package/dist/utils/requireAccess.js +13 -0
- package/dist/utils/resolveProvider.d.ts +6 -0
- package/dist/utils/resolveProvider.d.ts.map +1 -0
- package/dist/utils/resolveProvider.js +5 -0
- package/package.json +27 -12
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Provider } from './Provider.js';
|
|
2
|
+
export class Pixabay extends Provider {
|
|
3
|
+
constructor(apiKey){
|
|
4
|
+
super('pixabay', 'Pixabay', 'https://pixabay.com', apiKey);
|
|
5
|
+
}
|
|
6
|
+
getFetchBaseUrl() {
|
|
7
|
+
return 'https://pixabay.com';
|
|
8
|
+
}
|
|
9
|
+
getFetchHeaders() {
|
|
10
|
+
return {};
|
|
11
|
+
}
|
|
12
|
+
async getFeatured(filters) {
|
|
13
|
+
if (filters?.image_type || filters?.orientation || filters?.colors || filters?.category || filters?.order) {
|
|
14
|
+
return this.getSearch('', 1, filters);
|
|
15
|
+
}
|
|
16
|
+
const data = await this.fetch('GET', `/api?key=${this.getApiKey()}&per_page=${this.getFetchLimit()}`);
|
|
17
|
+
return {
|
|
18
|
+
images: this.formatResults(data.hits),
|
|
19
|
+
totalImages: null,
|
|
20
|
+
totalPages: null
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
async getSearch(query, page, filters) {
|
|
24
|
+
const params = new URLSearchParams({
|
|
25
|
+
key: this.getApiKey(),
|
|
26
|
+
q: query || '',
|
|
27
|
+
page: String(page),
|
|
28
|
+
per_page: String(this.getFetchLimit())
|
|
29
|
+
});
|
|
30
|
+
if (filters?.category) params.set('category', filters.category);
|
|
31
|
+
if (filters?.image_type) params.set('image_type', filters.image_type);
|
|
32
|
+
if (filters?.colors) params.set('colors', filters.colors);
|
|
33
|
+
if (filters?.orientation) params.set('orientation', filters.orientation);
|
|
34
|
+
if (filters?.order) params.set('order', filters.order);
|
|
35
|
+
const data = await this.fetch('GET', `/api?${params.toString()}`);
|
|
36
|
+
const totalHits = data.totalHits;
|
|
37
|
+
return {
|
|
38
|
+
images: this.formatResults(data.hits),
|
|
39
|
+
totalImages: totalHits,
|
|
40
|
+
totalPages: Math.min(Math.ceil(totalHits / this.getFetchLimit()), 100)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
formatResults(data) {
|
|
44
|
+
return data.map((image)=>({
|
|
45
|
+
id: image.id,
|
|
46
|
+
alt: '',
|
|
47
|
+
width: image.imageWidth,
|
|
48
|
+
height: image.imageHeight,
|
|
49
|
+
color: '#ccc',
|
|
50
|
+
likes: image.likes,
|
|
51
|
+
urls: {
|
|
52
|
+
view: image.webformatURL,
|
|
53
|
+
original: image.imageURL || image.largeImageURL,
|
|
54
|
+
download: image.imageURL || image.largeImageURL
|
|
55
|
+
},
|
|
56
|
+
attribution: {
|
|
57
|
+
name: image.user,
|
|
58
|
+
link: `https://pixabay.com/users/${image.user}-${image.user_id}/`
|
|
59
|
+
},
|
|
60
|
+
avatar: image.userImageURL
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ProviderResult } from '../../types.js';
|
|
2
|
+
export type Resolver = () => string | undefined;
|
|
3
|
+
export declare class Provider {
|
|
4
|
+
protected apiKey?: Resolver;
|
|
5
|
+
key: string;
|
|
6
|
+
name: string;
|
|
7
|
+
url: string;
|
|
8
|
+
constructor(key: string, name: string, url: string, apiKey?: Resolver);
|
|
9
|
+
fetch(method: string, urlPath: string, data?: object): Promise<unknown>;
|
|
10
|
+
get isConfigured(): boolean;
|
|
11
|
+
protected getApiKey(): string;
|
|
12
|
+
getFetchBaseUrl(): string;
|
|
13
|
+
getFetchHeaders(): Record<string, string>;
|
|
14
|
+
getFetchLimit(): number;
|
|
15
|
+
getFeatured(_filters?: Record<string, unknown>): Promise<unknown>;
|
|
16
|
+
getSearch(_query: string, _page: number): Promise<unknown>;
|
|
17
|
+
trackDownload(_url: string): null;
|
|
18
|
+
formatResults(_data: object): ProviderResult[];
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=Provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../../src/endpoints/handler/Provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,MAAM,MAAM,QAAQ,GAAG,MAAM,MAAM,GAAG,SAAS,CAAA;AAE/C,qBAAa,QAAQ;IACnB,SAAS,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAA;IAC3B,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;gBAEC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ;IAO/D,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAU7E,IAAI,YAAY,IAAI,OAAO,CAE1B;IAED,SAAS,CAAC,SAAS,IAAI,MAAM;IAU7B,eAAe,IAAI,MAAM;IAIzB,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAIzC,aAAa,IAAI,MAAM;IAIvB,WAAW,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAIjE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI1D,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIjC,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,EAAE;CAG/C"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export class Provider {
|
|
2
|
+
apiKey;
|
|
3
|
+
key;
|
|
4
|
+
name;
|
|
5
|
+
url;
|
|
6
|
+
constructor(key, name, url, apiKey){
|
|
7
|
+
this.key = key;
|
|
8
|
+
this.name = name;
|
|
9
|
+
this.url = url;
|
|
10
|
+
this.apiKey = apiKey;
|
|
11
|
+
}
|
|
12
|
+
async fetch(method, urlPath, data) {
|
|
13
|
+
const response = await fetch(new URL(urlPath, this.getFetchBaseUrl()), {
|
|
14
|
+
method,
|
|
15
|
+
headers: this.getFetchHeaders(),
|
|
16
|
+
...data && {
|
|
17
|
+
body: JSON.stringify(data)
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return response.json();
|
|
21
|
+
}
|
|
22
|
+
get isConfigured() {
|
|
23
|
+
return Boolean(this.apiKey?.());
|
|
24
|
+
}
|
|
25
|
+
getApiKey() {
|
|
26
|
+
const key = this.apiKey?.();
|
|
27
|
+
if (!key) {
|
|
28
|
+
throw new Error(`Provider "${this.key}" is not configured`);
|
|
29
|
+
}
|
|
30
|
+
return key;
|
|
31
|
+
}
|
|
32
|
+
getFetchBaseUrl() {
|
|
33
|
+
return '';
|
|
34
|
+
}
|
|
35
|
+
getFetchHeaders() {
|
|
36
|
+
return {};
|
|
37
|
+
}
|
|
38
|
+
getFetchLimit() {
|
|
39
|
+
return 24;
|
|
40
|
+
}
|
|
41
|
+
getFeatured(_filters) {
|
|
42
|
+
return Promise.resolve({});
|
|
43
|
+
}
|
|
44
|
+
getSearch(_query, _page) {
|
|
45
|
+
return Promise.resolve({});
|
|
46
|
+
}
|
|
47
|
+
trackDownload(_url) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
formatResults(_data) {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ProviderResult, UnsplashFilters, UnsplashResult } from '../../types.js';
|
|
2
|
+
import type { Resolver } from './Provider.js';
|
|
3
|
+
import { Provider } from './Provider.js';
|
|
4
|
+
export declare class Unsplash extends Provider {
|
|
5
|
+
constructor(apiKey: Resolver);
|
|
6
|
+
getFetchBaseUrl(): string;
|
|
7
|
+
getFetchHeaders(): Record<string, string>;
|
|
8
|
+
getFeatured(filters?: UnsplashFilters): Promise<unknown>;
|
|
9
|
+
getSearch(query: string, page: number, filters?: UnsplashFilters): Promise<unknown>;
|
|
10
|
+
trackDownload(url: string): null;
|
|
11
|
+
formatResults(data: UnsplashResult[]): ProviderResult[];
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=Unsplash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Unsplash.d.ts","sourceRoot":"","sources":["../../../src/endpoints/handler/Unsplash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACrF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAIxC,qBAAa,QAAS,SAAQ,QAAQ;gBACxB,MAAM,EAAE,QAAQ;IAInB,eAAe,IAAI,MAAM;IAIzB,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAInC,WAAW,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC;IAoCxD,SAAS,CACtB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,OAAO,CAAC;IAmBV,aAAa,CAAC,GAAG,EAAE,MAAM;IAMzB,aAAa,CAAC,IAAI,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE;CAqBjE"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Provider } from './Provider.js';
|
|
2
|
+
const UTMParams = 'utm_source=rubixstudios-payload-images&utm_medium=referral';
|
|
3
|
+
export class Unsplash extends Provider {
|
|
4
|
+
constructor(apiKey){
|
|
5
|
+
super('unsplash', 'Unsplash', 'https://unsplash.com', apiKey);
|
|
6
|
+
}
|
|
7
|
+
getFetchBaseUrl() {
|
|
8
|
+
return 'https://api.unsplash.com';
|
|
9
|
+
}
|
|
10
|
+
getFetchHeaders() {
|
|
11
|
+
return {
|
|
12
|
+
Authorization: `Client-ID ${this.getApiKey()}`
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
async getFeatured(filters) {
|
|
16
|
+
if (filters?.color || filters?.orientation) {
|
|
17
|
+
const params = new URLSearchParams({
|
|
18
|
+
per_page: String(this.getFetchLimit()),
|
|
19
|
+
query: 'featured'
|
|
20
|
+
});
|
|
21
|
+
if (filters.color) {
|
|
22
|
+
params.set('color', filters.color);
|
|
23
|
+
}
|
|
24
|
+
if (filters.orientation) {
|
|
25
|
+
params.set('orientation', filters.orientation);
|
|
26
|
+
}
|
|
27
|
+
const data = await this.fetch('GET', `/search/photos?${params.toString()}`);
|
|
28
|
+
return {
|
|
29
|
+
images: this.formatResults(data.results),
|
|
30
|
+
countOfImages: null,
|
|
31
|
+
countOfPages: null
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const data = await this.fetch('GET', `/photos/random?featured=true&count=${this.getFetchLimit()}`);
|
|
35
|
+
return {
|
|
36
|
+
images: this.formatResults(data),
|
|
37
|
+
countOfImages: null,
|
|
38
|
+
countOfPages: null
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async getSearch(query, page, filters) {
|
|
42
|
+
const params = new URLSearchParams({
|
|
43
|
+
per_page: String(this.getFetchLimit()),
|
|
44
|
+
page: String(page),
|
|
45
|
+
query
|
|
46
|
+
});
|
|
47
|
+
if (filters?.color) params.set('color', filters.color);
|
|
48
|
+
if (filters?.orientation) params.set('orientation', filters.orientation);
|
|
49
|
+
const data = await this.fetch('GET', `/search/photos?${params.toString()}`);
|
|
50
|
+
return {
|
|
51
|
+
images: this.formatResults(data.results),
|
|
52
|
+
totalImages: data.total,
|
|
53
|
+
totalPages: Math.min(data.total_pages, 100)
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
trackDownload(url) {
|
|
57
|
+
const downloadUrl = new URL(url);
|
|
58
|
+
void this.fetch('GET', `${downloadUrl.pathname}${downloadUrl.search}`);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
formatResults(data) {
|
|
62
|
+
return data.map((image)=>({
|
|
63
|
+
id: image.id,
|
|
64
|
+
alt: image.alt_description || '',
|
|
65
|
+
width: image.width,
|
|
66
|
+
height: image.height,
|
|
67
|
+
color: image.color,
|
|
68
|
+
likes: image.likes,
|
|
69
|
+
avatar: image.user?.profile_image?.medium ?? undefined,
|
|
70
|
+
urls: {
|
|
71
|
+
view: image.urls?.thumb,
|
|
72
|
+
original: image.urls?.full,
|
|
73
|
+
download: `${image.links?.download}?${UTMParams}`,
|
|
74
|
+
downloadLocation: `${image.links.download_location}&${UTMParams}`
|
|
75
|
+
},
|
|
76
|
+
attribution: {
|
|
77
|
+
name: image.user?.name,
|
|
78
|
+
link: `${image.user?.links?.html}?${UTMParams}`
|
|
79
|
+
}
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../src/endpoints/providers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAKvC,eAAO,MAAM,SAAS,EAAE,QAAQ,EAwI/B,CAAA"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { getProviders } from '../utils/getProviders.js';
|
|
2
|
+
import { requireAccess } from '../utils/requireAccess.js';
|
|
3
|
+
import { resolveProvider } from '../utils/resolveProvider.js';
|
|
4
|
+
export const providers = [
|
|
5
|
+
{
|
|
6
|
+
path: '/providers',
|
|
7
|
+
method: 'get',
|
|
8
|
+
handler: async (req)=>{
|
|
9
|
+
const denied = await requireAccess(req);
|
|
10
|
+
if (denied) return denied;
|
|
11
|
+
const providerKeys = req.payload?.config?.custom?.providerKeys;
|
|
12
|
+
const providers = getProviders(providerKeys);
|
|
13
|
+
return Response.json({
|
|
14
|
+
data: providers,
|
|
15
|
+
error: null
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
path: '/providers/:provider/featured',
|
|
21
|
+
method: 'get',
|
|
22
|
+
handler: async (req)=>{
|
|
23
|
+
const denied = await requireAccess(req);
|
|
24
|
+
if (denied) return denied;
|
|
25
|
+
const provider = resolveProvider(req);
|
|
26
|
+
if (!provider) {
|
|
27
|
+
return Response.json({
|
|
28
|
+
data: null,
|
|
29
|
+
error: 'Provider not supported.'
|
|
30
|
+
}, {
|
|
31
|
+
status: 404
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (!provider.isConfigured) {
|
|
35
|
+
return Response.json({
|
|
36
|
+
data: null,
|
|
37
|
+
error: 'Provider not configured.'
|
|
38
|
+
}, {
|
|
39
|
+
status: 500
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const data = await provider.getFeatured({
|
|
43
|
+
category: req.query.category,
|
|
44
|
+
color: req.query.color,
|
|
45
|
+
colors: req.query.colors,
|
|
46
|
+
image_type: req.query.image_type,
|
|
47
|
+
order: req.query.order,
|
|
48
|
+
orientation: req.query.orientation,
|
|
49
|
+
size: req.query.size
|
|
50
|
+
});
|
|
51
|
+
return Response.json({
|
|
52
|
+
data,
|
|
53
|
+
error: null
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
path: '/providers/:provider/search',
|
|
59
|
+
method: 'get',
|
|
60
|
+
handler: async (req)=>{
|
|
61
|
+
const denied = await requireAccess(req);
|
|
62
|
+
if (denied) return denied;
|
|
63
|
+
const provider = resolveProvider(req);
|
|
64
|
+
if (!provider) {
|
|
65
|
+
return Response.json({
|
|
66
|
+
data: null,
|
|
67
|
+
error: 'Provider not supported.'
|
|
68
|
+
}, {
|
|
69
|
+
status: 404
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (!provider.isConfigured) {
|
|
73
|
+
return Response.json({
|
|
74
|
+
data: null,
|
|
75
|
+
error: 'Provider not configured.'
|
|
76
|
+
}, {
|
|
77
|
+
status: 500
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
const data = await provider.getSearch(req.query.query, Number(req.query.page ?? 1), {
|
|
81
|
+
category: req.query.category,
|
|
82
|
+
color: req.query.color,
|
|
83
|
+
colors: req.query.colors,
|
|
84
|
+
image_type: req.query.image_type,
|
|
85
|
+
order: req.query.order,
|
|
86
|
+
orientation: req.query.orientation,
|
|
87
|
+
size: req.query.size
|
|
88
|
+
});
|
|
89
|
+
return Response.json({
|
|
90
|
+
data,
|
|
91
|
+
error: null
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
path: '/providers/:provider/track-download',
|
|
97
|
+
method: 'get',
|
|
98
|
+
handler: async (req)=>{
|
|
99
|
+
const denied = await requireAccess(req);
|
|
100
|
+
if (denied) return denied;
|
|
101
|
+
const provider = resolveProvider(req);
|
|
102
|
+
if (!provider) {
|
|
103
|
+
return Response.json({
|
|
104
|
+
data: null,
|
|
105
|
+
error: 'Provider not supported.'
|
|
106
|
+
}, {
|
|
107
|
+
status: 404
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
if (!provider.isConfigured) {
|
|
111
|
+
return Response.json({
|
|
112
|
+
data: null,
|
|
113
|
+
error: 'Provider not configured.'
|
|
114
|
+
}, {
|
|
115
|
+
status: 500
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
const data = provider.trackDownload(req.query.url);
|
|
119
|
+
return Response.json({
|
|
120
|
+
data,
|
|
121
|
+
error: null
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/exports/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ImageSearch } from '../components/ImageSearch/index.js';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +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,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,eAAO,MAAM,WAAW,GACrB,eAAc,WAAgB,MAC9B,gBAAgB,MAAM,KAAG,MAiDzB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { defaultPluginOptions } from './defaults.js';
|
|
2
|
+
import { providers } from './endpoints/providers.js';
|
|
3
|
+
export const imagePlugin = (pluginConfig = {})=>(incomingConfig)=>{
|
|
4
|
+
if (pluginConfig.disabled) return incomingConfig;
|
|
5
|
+
const mergedOptions = {
|
|
6
|
+
...defaultPluginOptions,
|
|
7
|
+
...pluginConfig
|
|
8
|
+
};
|
|
9
|
+
const settings = {
|
|
10
|
+
...incomingConfig
|
|
11
|
+
};
|
|
12
|
+
settings.custom = {
|
|
13
|
+
...settings.custom || {},
|
|
14
|
+
providerAccess: mergedOptions.access,
|
|
15
|
+
providerKeys: {
|
|
16
|
+
pexels: mergedOptions.pexels,
|
|
17
|
+
unsplash: mergedOptions.unsplash,
|
|
18
|
+
pixabay: mergedOptions.pixabay
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
settings.collections = (settings.collections || []).map((collection)=>{
|
|
22
|
+
const upload = collection.upload;
|
|
23
|
+
if (!upload) return collection;
|
|
24
|
+
const uploadObj = upload === true ? {} : typeof upload === 'object' ? upload : undefined;
|
|
25
|
+
const modifiedCollection = {
|
|
26
|
+
...collection,
|
|
27
|
+
upload: {
|
|
28
|
+
...uploadObj || {},
|
|
29
|
+
admin: {
|
|
30
|
+
...uploadObj?.admin || {},
|
|
31
|
+
components: {
|
|
32
|
+
...uploadObj?.admin?.components || {},
|
|
33
|
+
controls: [
|
|
34
|
+
...uploadObj?.admin?.components?.controls || [],
|
|
35
|
+
'@rubixstudios/payload-images/client#ImageSearch'
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
return modifiedCollection;
|
|
42
|
+
});
|
|
43
|
+
settings.endpoints = [
|
|
44
|
+
...settings.endpoints || [],
|
|
45
|
+
...providers
|
|
46
|
+
];
|
|
47
|
+
return settings;
|
|
48
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/lib/cache.ts"],"names":[],"mappings":"AAEA,qBAAa,YAAY;IACvB,OAAO,CAAC,eAAe;IAIvB,MAAM,CAAC,KAAK,EAAE,MAAM;IAKpB,GAAG,CAAC,KAAK,EAAE,MAAM;IAsBjB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;CAWtD"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const VERSION = '2';
|
|
2
|
+
export class CacheManager {
|
|
3
|
+
getVersionedKey(query) {
|
|
4
|
+
return `${VERSION}${query}`;
|
|
5
|
+
}
|
|
6
|
+
exists(query) {
|
|
7
|
+
const key = this.getVersionedKey(query);
|
|
8
|
+
return localStorage.getItem(key) !== null;
|
|
9
|
+
}
|
|
10
|
+
get(query) {
|
|
11
|
+
const key = this.getVersionedKey(query);
|
|
12
|
+
const itemStr = localStorage.getItem(key);
|
|
13
|
+
if (!itemStr) return null;
|
|
14
|
+
let item;
|
|
15
|
+
try {
|
|
16
|
+
item = JSON.parse(itemStr);
|
|
17
|
+
} catch {
|
|
18
|
+
localStorage.removeItem(key);
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
if (item.expiry && Date.now() > item.expiry) {
|
|
22
|
+
localStorage.removeItem(key);
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
return item.value;
|
|
26
|
+
}
|
|
27
|
+
set(query, data, ttl) {
|
|
28
|
+
const key = this.getVersionedKey(query);
|
|
29
|
+
localStorage.setItem(key, JSON.stringify({
|
|
30
|
+
value: data,
|
|
31
|
+
expiry: ttl ? Date.now() + ttl : undefined
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import type { Access } from 'payload';
|
|
2
|
+
export type ImageConfig = {
|
|
3
|
+
access?: Access;
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
openverse?: string;
|
|
6
|
+
pexels?: string;
|
|
7
|
+
pixabay?: string;
|
|
8
|
+
unsplash?: string;
|
|
9
|
+
};
|
|
10
|
+
export type ProviderKeys = {
|
|
11
|
+
unsplash?: string;
|
|
12
|
+
openverse?: string;
|
|
13
|
+
pexels?: string;
|
|
14
|
+
pixabay?: string;
|
|
15
|
+
};
|
|
16
|
+
export interface OpenverseResponse {
|
|
17
|
+
result_count: number;
|
|
18
|
+
page_count: number;
|
|
19
|
+
page_size: number;
|
|
20
|
+
page: number;
|
|
21
|
+
results: OpenverseResult[];
|
|
22
|
+
}
|
|
23
|
+
export interface OpenverseResult {
|
|
24
|
+
id: string;
|
|
25
|
+
title: string | null;
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
thumbnail: string;
|
|
29
|
+
url: string;
|
|
30
|
+
background_color?: string | null;
|
|
31
|
+
creator: string | null;
|
|
32
|
+
creator_url: string | null;
|
|
33
|
+
foreign_landing_url: string | null;
|
|
34
|
+
source: string;
|
|
35
|
+
}
|
|
36
|
+
export declare const PexelsColours: {
|
|
37
|
+
label: string;
|
|
38
|
+
value: string;
|
|
39
|
+
}[];
|
|
40
|
+
export type PexelsFilters = {
|
|
41
|
+
orientation?: string;
|
|
42
|
+
size?: string;
|
|
43
|
+
color?: string;
|
|
44
|
+
};
|
|
45
|
+
export declare const PexelsOrientation: {
|
|
46
|
+
label: string;
|
|
47
|
+
value: string;
|
|
48
|
+
}[];
|
|
49
|
+
export declare const PexelsSize: {
|
|
50
|
+
label: string;
|
|
51
|
+
value: string;
|
|
52
|
+
}[];
|
|
53
|
+
export interface PexelsResult {
|
|
54
|
+
id: string;
|
|
55
|
+
alt: string;
|
|
56
|
+
width: number;
|
|
57
|
+
height: number;
|
|
58
|
+
avg_color: string;
|
|
59
|
+
url: string;
|
|
60
|
+
src: {
|
|
61
|
+
medium: string;
|
|
62
|
+
original: string;
|
|
63
|
+
};
|
|
64
|
+
photographer: string;
|
|
65
|
+
photographer_url: string;
|
|
66
|
+
}
|
|
67
|
+
export declare const PixabayCategories: {
|
|
68
|
+
label: string;
|
|
69
|
+
value: string;
|
|
70
|
+
}[];
|
|
71
|
+
export declare const PixabayColours: {
|
|
72
|
+
label: string;
|
|
73
|
+
value: string;
|
|
74
|
+
}[];
|
|
75
|
+
export type PixabayFilters = {
|
|
76
|
+
image_type?: string;
|
|
77
|
+
orientation?: string;
|
|
78
|
+
category?: string;
|
|
79
|
+
colors?: string;
|
|
80
|
+
order?: string;
|
|
81
|
+
};
|
|
82
|
+
export declare const PixabayImageType: {
|
|
83
|
+
label: string;
|
|
84
|
+
value: string;
|
|
85
|
+
}[];
|
|
86
|
+
export declare const PixabayOrder: {
|
|
87
|
+
label: string;
|
|
88
|
+
value: string;
|
|
89
|
+
}[];
|
|
90
|
+
export declare const PixabayOrientation: {
|
|
91
|
+
label: string;
|
|
92
|
+
value: string;
|
|
93
|
+
}[];
|
|
94
|
+
export interface PixabayResult {
|
|
95
|
+
id: string;
|
|
96
|
+
imageWidth: number;
|
|
97
|
+
imageHeight: number;
|
|
98
|
+
webformatURL: string;
|
|
99
|
+
largeImageURL: string;
|
|
100
|
+
likes: number;
|
|
101
|
+
imageURL: string;
|
|
102
|
+
user: string;
|
|
103
|
+
user_id: number;
|
|
104
|
+
userImageURL: string;
|
|
105
|
+
}
|
|
106
|
+
export interface ProviderResult {
|
|
107
|
+
id: string;
|
|
108
|
+
alt: string;
|
|
109
|
+
width: number;
|
|
110
|
+
height: number;
|
|
111
|
+
color: string;
|
|
112
|
+
likes?: number;
|
|
113
|
+
urls: {
|
|
114
|
+
view: string;
|
|
115
|
+
original: string;
|
|
116
|
+
download: string;
|
|
117
|
+
downloadLocation?: string;
|
|
118
|
+
};
|
|
119
|
+
avatar?: string;
|
|
120
|
+
attribution: {
|
|
121
|
+
name: string;
|
|
122
|
+
link: string;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export declare const UnsplashColours: {
|
|
126
|
+
label: string;
|
|
127
|
+
value: string;
|
|
128
|
+
}[];
|
|
129
|
+
export declare const UnsplashOrientation: {
|
|
130
|
+
label: string;
|
|
131
|
+
value: string;
|
|
132
|
+
}[];
|
|
133
|
+
export type UnsplashFilters = {
|
|
134
|
+
color?: string;
|
|
135
|
+
orientation?: string;
|
|
136
|
+
};
|
|
137
|
+
export interface UnsplashResult {
|
|
138
|
+
id: string;
|
|
139
|
+
alt_description: string;
|
|
140
|
+
width: number;
|
|
141
|
+
height: number;
|
|
142
|
+
color: string;
|
|
143
|
+
likes?: number;
|
|
144
|
+
urls: {
|
|
145
|
+
thumb: string;
|
|
146
|
+
full: string;
|
|
147
|
+
};
|
|
148
|
+
links: {
|
|
149
|
+
download: string;
|
|
150
|
+
download_location: string;
|
|
151
|
+
};
|
|
152
|
+
user: {
|
|
153
|
+
name: string;
|
|
154
|
+
profile_image?: {
|
|
155
|
+
small: string;
|
|
156
|
+
medium: string;
|
|
157
|
+
large: string;
|
|
158
|
+
};
|
|
159
|
+
links: {
|
|
160
|
+
html: string;
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC,MAAM,MAAM,WAAW,GAAG;IACxB,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,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,eAAe,EAAE,CAAA;CAC3B;AAED,MAAM,WAAW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