Skip to content

Commit 2e6714c

Browse files
committed
feat: add new provider filerobot
1 parent cef2f82 commit 2e6714c

File tree

7 files changed

+102
-1
lines changed

7 files changed

+102
-1
lines changed

docs/pages/index.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ useSeoMeta({
1616
const source = ref('npx nuxi@latest module add image')
1717
const { copy, copied } = useClipboard({ source })
1818
19-
const providers = ['caisy', 'bunny', 'cloudflare', 'cloudimage', 'cloudinary', 'directus', 'edgio', 'fastly', 'glide', 'gumlet', 'hygraph', 'imageengine', 'imagekit', 'imgix', 'ipx', 'netlify', 'prepr', 'prismic', 'sanity', 'storyblok', 'strapi', 'twicpics', 'unsplash', 'uploadcare', 'vercel', 'weserv']
19+
const providers = ['caisy', 'bunny', 'cloudflare', 'cloudimage', 'cloudinary', 'directus', 'edgio', 'fastly', 'filerobot', 'glide', 'gumlet', 'hygraph', 'imageengine', 'imagekit', 'imgix', 'ipx', 'netlify', 'prepr', 'prismic', 'sanity', 'storyblok', 'strapi', 'twicpics', 'unsplash', 'uploadcare', 'vercel', 'weserv']
2020
// Disabling because svg to png does not work now with SSG
2121
// Related issue: https://github.com/unjs/ipx/issues/160
2222
// const img = useImage()

playground/nuxt.config.ts

+3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ export default defineNuxtConfig({
6868
fastly: {
6969
baseURL: 'https://www.fastly.io',
7070
},
71+
filerobot: {
72+
baseURL: 'https://fesrinkeb.filerobot.com/',
73+
},
7174
glide: {
7275
baseURL: 'https://glide.herokuapp.com/1.0/',
7376
},

playground/providers.ts

+35
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,41 @@ export const providers: Provider[] = [
244244
{ src: '/plant.jpeg' },
245245
],
246246
},
247+
// Filerobot
248+
{
249+
name: 'filerobot',
250+
samples: [
251+
{
252+
src: 'https://fesrinkeb.filerobot.com/monitoring3/boat-2023-03-06T15%3A03%3A12.6382894Z?vh=b3583b',
253+
width: 400,
254+
height: 250,
255+
densities: 'x1 x2',
256+
fit: 'contain',
257+
quality: 65,
258+
format: 'webp',
259+
},
260+
{
261+
src: '/monitoring3/boat-2023-03-06T15%3A03%3A12.6382894Z?vh=b3583b',
262+
width: 500,
263+
height: 500,
264+
fit: 'contain',
265+
},
266+
{
267+
src: '/monitoring3/boat-2023-03-06T15%3A03%3A12.6382894Z?vh=b3583b',
268+
width: 800,
269+
height: 800,
270+
quality: 75,
271+
fit: 'cover',
272+
},
273+
{
274+
src: '/monitoring3/boat-2023-03-06T15%3A03%3A12.6382894Z?vh=b3583b',
275+
width: 300,
276+
height: 300,
277+
format: 'webp',
278+
fit: 'fill',
279+
},
280+
],
281+
},
247282
// ImageKit
248283
{
249284
name: 'imagekit',

src/provider.ts

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const BuiltInProviders = [
2222
'directus',
2323
'edgio',
2424
'fastly',
25+
'filerobot',
2526
'glide',
2627
'gumlet',
2728
'hygraph',

src/runtime/providers/filerobot.ts

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { joinURL, hasProtocol } from 'ufo'
2+
import type { ProviderGetImage } from '../../module'
3+
import { createOperationsGenerator } from '#image'
4+
5+
const operationsGenerator = createOperationsGenerator({
6+
keyMap: {
7+
fit: 'func',
8+
format: 'force_format',
9+
quality: 'q',
10+
width: 'w',
11+
height: 'h',
12+
},
13+
valueMap: {
14+
fit: {
15+
cover: 'crop',
16+
contain: 'fit',
17+
fill: 'cover',
18+
inside: 'bound',
19+
outside: 'boundmin',
20+
},
21+
},
22+
joinWith: '&',
23+
formatter: (key, value) => `${key}=${value}`,
24+
})
25+
26+
export const getImage: ProviderGetImage = (src, {
27+
modifiers = {},
28+
baseURL = '',
29+
} = {}) => {
30+
const operations = operationsGenerator(modifiers)
31+
const query = (operations ? ('?' + operations) : '')
32+
33+
if (import.meta.dev) {
34+
if (!baseURL) {
35+
console.warn(`[fielrobot] <baseURL> is required to build image URL`)
36+
}
37+
}
38+
39+
if (hasProtocol(src)) {
40+
return {
41+
url: joinURL(src) + query,
42+
}
43+
}
44+
45+
return {
46+
url: joinURL(baseURL, src) + query,
47+
}
48+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"requests": [
3+
"https://fesrinkeb.filerobot.com/monitoring3/boat-2023-03-06T15%3A03%3A12.6382894Z?vh=b3583b?width=400&height=250&force_format=webp&q=65&func=fit"
4+
],
5+
"sources": [
6+
"https://fesrinkeb.filerobot.com/monitoring3/boat-2023-03-06T15%3A03%3A12.6382894Z?vh=b3583b?width=400&height=250&force_format=webp&q=65&func=fit"
7+
],
8+
}

test/providers.ts

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const images = [
99
cloudinary: { url: '/f_auto,q_auto/test' },
1010
twicpics: { url: '/test.png' },
1111
fastly: { url: '/test.png' },
12+
filerobot: { url: '/monitoring3/boat-2023-03-06T15%3A03%3A12.6382894Z?vh=b3583b' },
1213
glide: { url: '/test.png' },
1314
gumlet: { url: '/test.png' },
1415
imgix: { url: '/test.png' },
@@ -45,6 +46,7 @@ export const images = [
4546
cloudinary: { url: '/f_auto,q_auto,w_200/test' },
4647
twicpics: { url: '/test.png?twic=v1/cover=200x-' },
4748
fastly: { url: '/test.png?width=200' },
49+
filerobot: { url: '/monitoring3/boat-2023-03-06T15%3A03%3A12.6382894Z?vh=b3583b?w=200' },
4850
glide: { url: '/test.png?w=200' },
4951
gumlet: { url: '/test.png?w=200' },
5052
imgix: { url: '/test.png?w=200' },
@@ -81,6 +83,7 @@ export const images = [
8183
cloudinary: { url: '/f_auto,q_auto,h_200/test' },
8284
twicpics: { url: '/test.png?twic=v1/cover=-x200' },
8385
fastly: { url: '/test.png?height=200' },
86+
filerobot: { url: '/monitoring3/boat-2023-03-06T15%3A03%3A12.6382894Z?vh=b3583b?h=200' },
8487
glide: { url: '/test.png?h=200' },
8588
gumlet: { url: '/test.png?h=200' },
8689
imgix: { url: '/test.png?h=200' },
@@ -117,6 +120,7 @@ export const images = [
117120
cloudinary: { url: '/f_auto,q_auto,w_200,h_200/test' },
118121
twicpics: { url: '/test.png?twic=v1/cover=200x200' },
119122
fastly: { url: '/test.png?width=200&height=200' },
123+
filerobot: { url: '/monitoring3/boat-2023-03-06T15%3A03%3A12.6382894Z?vh=b3583b?w=200&h=200' },
120124
glide: { url: '/test.png?w=200&h=200' },
121125
gumlet: { url: '/test.png?w=200&h=200' },
122126
imgix: { url: '/test.png?w=200&h=200' },
@@ -153,6 +157,7 @@ export const images = [
153157
cloudinary: { url: '/f_auto,q_auto,w_200,h_200,c_scale/test' },
154158
twicpics: { url: '/test.png?twic=v1/inside=200x200' },
155159
fastly: { url: '/test.png?width=200&height=200&fit=bounds' },
160+
filerobot: { url: '/monitoring3/boat-2023-03-06T15%3A03%3A12.6382894Z?vh=b3583b?w=200&h=200&func=fit' },
156161
glide: { url: '/test.png?w=200&h=200&fit=contain' },
157162
gumlet: { url: '/test.png?w=200&h=200&fit=fill' },
158163
imgix: { url: '/test.png?w=200&h=200&fit=fill' },
@@ -189,6 +194,7 @@ export const images = [
189194
cloudinary: { url: '/f_jpg,q_auto,w_200,h_200,c_scale/test' },
190195
twicpics: { url: '/test.png?twic=v1/output=jpeg/inside=200x200' },
191196
fastly: { url: '/test.png?width=200&height=200&fit=bounds&format=jpeg' },
197+
filerobot: { url: '/monitoring3/boat-2023-03-06T15%3A03%3A12.6382894Z?vh=b3583b?w=200&h=200&func=fit&force_format=jpeg' },
192198
glide: { url: '/test.png?w=200&h=200&fit=contain&fm=jpeg' },
193199
gumlet: { url: '/test.png?w=200&h=200&fit=fill&format=jpeg' },
194200
imgix: { url: '/test.png?w=200&h=200&fit=fill&fm=jpeg' },

0 commit comments

Comments
 (0)