@opensea/seadn 2.0.8 → 2.1.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/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/sdk.spec.ts +20 -0
- package/src/sdk.ts +30 -9
package/dist/index.d.mts
CHANGED
|
@@ -6,7 +6,8 @@ type MediaParams = {
|
|
|
6
6
|
format?: MediaFormat;
|
|
7
7
|
quality?: number | `${number}`;
|
|
8
8
|
fit?: MediaFit;
|
|
9
|
+
t?: number;
|
|
9
10
|
};
|
|
10
|
-
declare function optimize(image: string | URL, { width, height, format, quality, fit }: MediaParams): string;
|
|
11
|
+
declare function optimize(image: string | URL, { width, height, format, quality, fit, t }: MediaParams): string;
|
|
11
12
|
|
|
12
13
|
export { type MediaFit, type MediaFormat, type MediaParams, optimize };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,8 @@ type MediaParams = {
|
|
|
6
6
|
format?: MediaFormat;
|
|
7
7
|
quality?: number | `${number}`;
|
|
8
8
|
fit?: MediaFit;
|
|
9
|
+
t?: number;
|
|
9
10
|
};
|
|
10
|
-
declare function optimize(image: string | URL, { width, height, format, quality, fit }: MediaParams): string;
|
|
11
|
+
declare function optimize(image: string | URL, { width, height, format, quality, fit, t }: MediaParams): string;
|
|
11
12
|
|
|
12
13
|
export { type MediaFit, type MediaFormat, type MediaParams, optimize };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var s=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var h=(e,n)=>{for(var r in n)s(e,r,{get:n[r],enumerable:!0})},x=(e,n,r,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of m(n))!l.call(e,t)&&t!==r&&s(e,t,{get:()=>n[t],enumerable:!(o=b(n,t))||o.enumerable});return e};var R=e=>x(s({},"__esModule",{value:!0}),e);var g={};h(g,{optimize:()=>d});module.exports=R(g);function d(e,{width:n,height:r,format:o,quality:t,fit:a,t:f}){try{typeof e=="string"&&(e=new URL(e))}catch(w){return e.toString()}if(!(e instanceof URL))return e;let u=S(e);if(!L(e)&&!u)return e.toString();let i=new URLSearchParams;if(r!==void 0&&i.set("h",String(r)),n!==void 0&&i.set("w",String(n)),o!==void 0&&i.set("format",o),t){if(Number(t)<=0||Number(t)>100)throw new Error("Quality has to be a positive number between 1 and 100");i.set("q",String(t))}if(a!==void 0&&i.set("fit",a),f!==void 0)u&&i.set("t",String(f));else if(c(e))return e.toString();return e.search=i.toString(),e.toString()}function c(e){let n=p(e);return n==="mp4"||n==="mov"}function S(e){return c(e)}function L(e){if(!U(e))return!1;switch(p(e)){case"png":case"jpeg":case"webp":case"avif":case"ico":case"gif":case void 0:return!0;default:return!1}}function p(e){let n=e.pathname.split(".");if(!(n.length<=1))return n[n.length-1]}function U(e){return e.hostname.endsWith("seadn.io")}0&&(module.exports={optimize});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/sdk.ts"],"sourcesContent":["export { optimize, MediaParams, MediaFormat, MediaFit } from \"./sdk\";\n","export type MediaFormat = \"webp\" | \"avif\" | \"jpeg\" | \"png\";\nexport type MediaFit = \"cover\" | \"contain\" | \"fill\" | \"inside\" | \"outside\";\n\nexport type MediaParams = {\n width?: number | `${number}`;\n height?: number | `${number}`;\n format?: MediaFormat;\n quality?: number | `${number}`;\n fit?: MediaFit;\n};\n\nexport function optimize(\n image: string | URL,\n { width, height, format, quality, fit }: MediaParams,\n): string {\n try {\n if (typeof image === \"string\") {\n image = new URL(image);\n }\n } catch {\n return image.toString();\n }\n\n if (!(image instanceof URL)) {\n return image;\n }\n\n if (!canBeResized(image)) {\n return image.toString();\n }\n\n const params = new URLSearchParams();\n if (height !== undefined) {\n params.set(\"h\", String(height));\n }\n if (width !== undefined) {\n params.set(\"w\", String(width));\n }\n if (format !== undefined) {\n params.set(\"format\", format);\n }\n if (quality) {\n if (Number(quality) <= 0 || Number(quality) > 100) {\n throw new Error(\"Quality has to be a positive number between 1 and 100\");\n }\n params.set(\"q\", String(quality));\n }\n if (fit !== undefined) {\n params.set(\"fit\", fit);\n }\n\n image.search = params.toString();\n return image.toString();\n}\n\nfunction
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/sdk.ts"],"sourcesContent":["export { optimize, MediaParams, MediaFormat, MediaFit } from \"./sdk\";\n","export type MediaFormat = \"webp\" | \"avif\" | \"jpeg\" | \"png\";\nexport type MediaFit = \"cover\" | \"contain\" | \"fill\" | \"inside\" | \"outside\";\n\nexport type MediaParams = {\n width?: number | `${number}`;\n height?: number | `${number}`;\n format?: MediaFormat;\n quality?: number | `${number}`;\n fit?: MediaFit;\n // Frame extraction time in seconds. Only applicable for videos\n t?: number;\n};\n\nexport function optimize(\n image: string | URL,\n { width, height, format, quality, fit, t }: MediaParams,\n): string {\n try {\n if (typeof image === \"string\") {\n image = new URL(image);\n }\n } catch {\n return image.toString();\n }\n\n if (!(image instanceof URL)) {\n return image;\n }\n\n const isFrameable = canExtractFrame(image);\n if (!canBeResized(image) && !isFrameable) {\n return image.toString();\n }\n\n const params = new URLSearchParams();\n if (height !== undefined) {\n params.set(\"h\", String(height));\n }\n if (width !== undefined) {\n params.set(\"w\", String(width));\n }\n if (format !== undefined) {\n params.set(\"format\", format);\n }\n if (quality) {\n if (Number(quality) <= 0 || Number(quality) > 100) {\n throw new Error(\"Quality has to be a positive number between 1 and 100\");\n }\n params.set(\"q\", String(quality));\n }\n if (fit !== undefined) {\n params.set(\"fit\", fit);\n }\n if (t !== undefined) {\n if (isFrameable) {\n params.set(\"t\", String(t));\n }\n } else if (isVideo(image)) {\n return image.toString();\n }\n\n image.search = params.toString();\n return image.toString();\n}\n\nfunction isVideo(url: URL): boolean {\n const extension = getExtension(url);\n return extension === \"mp4\" || extension === \"mov\";\n}\n\nfunction canExtractFrame(url: URL): boolean {\n return isVideo(url);\n}\n\nfunction canBeResized(url: URL): boolean {\n if (!isSeadnURL(url)) {\n return false;\n }\n const extension = getExtension(url);\n switch (extension) {\n case \"png\":\n case \"jpeg\":\n case \"webp\":\n case \"avif\":\n case \"ico\":\n case \"gif\":\n case undefined:\n return true;\n default:\n return false;\n }\n}\n\nfunction getExtension(url: URL): string | undefined {\n const split = url.pathname.split(\".\");\n if (split.length <= 1) {\n return undefined;\n }\n return split[split.length - 1];\n}\n\nexport function isSeadnURL(url: URL): boolean {\n return url.hostname.endsWith(\"seadn.io\");\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,IAAA,eAAAC,EAAAH,GCaO,SAASI,EACdC,EACA,CAAE,MAAAC,EAAO,OAAAC,EAAQ,OAAAC,EAAQ,QAAAC,EAAS,IAAAC,EAAK,EAAAC,CAAE,EACjC,CACR,GAAI,CACE,OAAON,GAAU,WACnBA,EAAQ,IAAI,IAAIA,CAAK,EAEzB,OAAQO,EAAA,CACN,OAAOP,EAAM,SAAS,CACxB,CAEA,GAAI,EAAEA,aAAiB,KACrB,OAAOA,EAGT,IAAMQ,EAAcC,EAAgBT,CAAK,EACzC,GAAI,CAACU,EAAaV,CAAK,GAAK,CAACQ,EAC3B,OAAOR,EAAM,SAAS,EAGxB,IAAMW,EAAS,IAAI,gBAUnB,GATIT,IAAW,QACbS,EAAO,IAAI,IAAK,OAAOT,CAAM,CAAC,EAE5BD,IAAU,QACZU,EAAO,IAAI,IAAK,OAAOV,CAAK,CAAC,EAE3BE,IAAW,QACbQ,EAAO,IAAI,SAAUR,CAAM,EAEzBC,EAAS,CACX,GAAI,OAAOA,CAAO,GAAK,GAAK,OAAOA,CAAO,EAAI,IAC5C,MAAM,IAAI,MAAM,uDAAuD,EAEzEO,EAAO,IAAI,IAAK,OAAOP,CAAO,CAAC,CACjC,CAIA,GAHIC,IAAQ,QACVM,EAAO,IAAI,MAAON,CAAG,EAEnBC,IAAM,OACJE,GACFG,EAAO,IAAI,IAAK,OAAOL,CAAC,CAAC,UAElBM,EAAQZ,CAAK,EACtB,OAAOA,EAAM,SAAS,EAGxB,OAAAA,EAAM,OAASW,EAAO,SAAS,EACxBX,EAAM,SAAS,CACxB,CAEA,SAASY,EAAQC,EAAmB,CAClC,IAAMC,EAAYC,EAAaF,CAAG,EAClC,OAAOC,IAAc,OAASA,IAAc,KAC9C,CAEA,SAASL,EAAgBI,EAAmB,CAC1C,OAAOD,EAAQC,CAAG,CACpB,CAEA,SAASH,EAAaG,EAAmB,CACvC,GAAI,CAACG,EAAWH,CAAG,EACjB,MAAO,GAGT,OADkBE,EAAaF,CAAG,EACf,CACjB,IAAK,MACL,IAAK,OACL,IAAK,OACL,IAAK,OACL,IAAK,MACL,IAAK,MACL,KAAK,OACH,MAAO,GACT,QACE,MAAO,EACX,CACF,CAEA,SAASE,EAAaF,EAA8B,CAClD,IAAMI,EAAQJ,EAAI,SAAS,MAAM,GAAG,EACpC,GAAI,EAAAI,EAAM,QAAU,GAGpB,OAAOA,EAAMA,EAAM,OAAS,CAAC,CAC/B,CAEO,SAASD,EAAWH,EAAmB,CAC5C,OAAOA,EAAI,SAAS,SAAS,UAAU,CACzC","names":["src_exports","__export","optimize","__toCommonJS","optimize","image","width","height","format","quality","fit","t","e","isFrameable","canExtractFrame","canBeResized","params","isVideo","url","extension","getExtension","isSeadnURL","split"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function
|
|
1
|
+
function c(e,{width:n,height:i,format:o,quality:r,fit:s,t:a}){try{typeof e=="string"&&(e=new URL(e))}catch(l){return e.toString()}if(!(e instanceof URL))return e;let f=p(e);if(!b(e)&&!f)return e.toString();let t=new URLSearchParams;if(i!==void 0&&t.set("h",String(i)),n!==void 0&&t.set("w",String(n)),o!==void 0&&t.set("format",o),r){if(Number(r)<=0||Number(r)>100)throw new Error("Quality has to be a positive number between 1 and 100");t.set("q",String(r))}if(s!==void 0&&t.set("fit",s),a!==void 0)f&&t.set("t",String(a));else if(u(e))return e.toString();return e.search=t.toString(),e.toString()}function u(e){let n=d(e);return n==="mp4"||n==="mov"}function p(e){return u(e)}function b(e){if(!m(e))return!1;switch(d(e)){case"png":case"jpeg":case"webp":case"avif":case"ico":case"gif":case void 0:return!0;default:return!1}}function d(e){let n=e.pathname.split(".");if(!(n.length<=1))return n[n.length-1]}function m(e){return e.hostname.endsWith("seadn.io")}export{c as optimize};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/sdk.ts"],"sourcesContent":["export type MediaFormat = \"webp\" | \"avif\" | \"jpeg\" | \"png\";\nexport type MediaFit = \"cover\" | \"contain\" | \"fill\" | \"inside\" | \"outside\";\n\nexport type MediaParams = {\n width?: number | `${number}`;\n height?: number | `${number}`;\n format?: MediaFormat;\n quality?: number | `${number}`;\n fit?: MediaFit;\n};\n\nexport function optimize(\n image: string | URL,\n { width, height, format, quality, fit }: MediaParams,\n): string {\n try {\n if (typeof image === \"string\") {\n image = new URL(image);\n }\n } catch {\n return image.toString();\n }\n\n if (!(image instanceof URL)) {\n return image;\n }\n\n if (!canBeResized(image)) {\n return image.toString();\n }\n\n const params = new URLSearchParams();\n if (height !== undefined) {\n params.set(\"h\", String(height));\n }\n if (width !== undefined) {\n params.set(\"w\", String(width));\n }\n if (format !== undefined) {\n params.set(\"format\", format);\n }\n if (quality) {\n if (Number(quality) <= 0 || Number(quality) > 100) {\n throw new Error(\"Quality has to be a positive number between 1 and 100\");\n }\n params.set(\"q\", String(quality));\n }\n if (fit !== undefined) {\n params.set(\"fit\", fit);\n }\n\n image.search = params.toString();\n return image.toString();\n}\n\nfunction
|
|
1
|
+
{"version":3,"sources":["../src/sdk.ts"],"sourcesContent":["export type MediaFormat = \"webp\" | \"avif\" | \"jpeg\" | \"png\";\nexport type MediaFit = \"cover\" | \"contain\" | \"fill\" | \"inside\" | \"outside\";\n\nexport type MediaParams = {\n width?: number | `${number}`;\n height?: number | `${number}`;\n format?: MediaFormat;\n quality?: number | `${number}`;\n fit?: MediaFit;\n // Frame extraction time in seconds. Only applicable for videos\n t?: number;\n};\n\nexport function optimize(\n image: string | URL,\n { width, height, format, quality, fit, t }: MediaParams,\n): string {\n try {\n if (typeof image === \"string\") {\n image = new URL(image);\n }\n } catch {\n return image.toString();\n }\n\n if (!(image instanceof URL)) {\n return image;\n }\n\n const isFrameable = canExtractFrame(image);\n if (!canBeResized(image) && !isFrameable) {\n return image.toString();\n }\n\n const params = new URLSearchParams();\n if (height !== undefined) {\n params.set(\"h\", String(height));\n }\n if (width !== undefined) {\n params.set(\"w\", String(width));\n }\n if (format !== undefined) {\n params.set(\"format\", format);\n }\n if (quality) {\n if (Number(quality) <= 0 || Number(quality) > 100) {\n throw new Error(\"Quality has to be a positive number between 1 and 100\");\n }\n params.set(\"q\", String(quality));\n }\n if (fit !== undefined) {\n params.set(\"fit\", fit);\n }\n if (t !== undefined) {\n if (isFrameable) {\n params.set(\"t\", String(t));\n }\n } else if (isVideo(image)) {\n return image.toString();\n }\n\n image.search = params.toString();\n return image.toString();\n}\n\nfunction isVideo(url: URL): boolean {\n const extension = getExtension(url);\n return extension === \"mp4\" || extension === \"mov\";\n}\n\nfunction canExtractFrame(url: URL): boolean {\n return isVideo(url);\n}\n\nfunction canBeResized(url: URL): boolean {\n if (!isSeadnURL(url)) {\n return false;\n }\n const extension = getExtension(url);\n switch (extension) {\n case \"png\":\n case \"jpeg\":\n case \"webp\":\n case \"avif\":\n case \"ico\":\n case \"gif\":\n case undefined:\n return true;\n default:\n return false;\n }\n}\n\nfunction getExtension(url: URL): string | undefined {\n const split = url.pathname.split(\".\");\n if (split.length <= 1) {\n return undefined;\n }\n return split[split.length - 1];\n}\n\nexport function isSeadnURL(url: URL): boolean {\n return url.hostname.endsWith(\"seadn.io\");\n}\n"],"mappings":"AAaO,SAASA,EACdC,EACA,CAAE,MAAAC,EAAO,OAAAC,EAAQ,OAAAC,EAAQ,QAAAC,EAAS,IAAAC,EAAK,EAAAC,CAAE,EACjC,CACR,GAAI,CACE,OAAON,GAAU,WACnBA,EAAQ,IAAI,IAAIA,CAAK,EAEzB,OAAQO,EAAA,CACN,OAAOP,EAAM,SAAS,CACxB,CAEA,GAAI,EAAEA,aAAiB,KACrB,OAAOA,EAGT,IAAMQ,EAAcC,EAAgBT,CAAK,EACzC,GAAI,CAACU,EAAaV,CAAK,GAAK,CAACQ,EAC3B,OAAOR,EAAM,SAAS,EAGxB,IAAMW,EAAS,IAAI,gBAUnB,GATIT,IAAW,QACbS,EAAO,IAAI,IAAK,OAAOT,CAAM,CAAC,EAE5BD,IAAU,QACZU,EAAO,IAAI,IAAK,OAAOV,CAAK,CAAC,EAE3BE,IAAW,QACbQ,EAAO,IAAI,SAAUR,CAAM,EAEzBC,EAAS,CACX,GAAI,OAAOA,CAAO,GAAK,GAAK,OAAOA,CAAO,EAAI,IAC5C,MAAM,IAAI,MAAM,uDAAuD,EAEzEO,EAAO,IAAI,IAAK,OAAOP,CAAO,CAAC,CACjC,CAIA,GAHIC,IAAQ,QACVM,EAAO,IAAI,MAAON,CAAG,EAEnBC,IAAM,OACJE,GACFG,EAAO,IAAI,IAAK,OAAOL,CAAC,CAAC,UAElBM,EAAQZ,CAAK,EACtB,OAAOA,EAAM,SAAS,EAGxB,OAAAA,EAAM,OAASW,EAAO,SAAS,EACxBX,EAAM,SAAS,CACxB,CAEA,SAASY,EAAQC,EAAmB,CAClC,IAAMC,EAAYC,EAAaF,CAAG,EAClC,OAAOC,IAAc,OAASA,IAAc,KAC9C,CAEA,SAASL,EAAgBI,EAAmB,CAC1C,OAAOD,EAAQC,CAAG,CACpB,CAEA,SAASH,EAAaG,EAAmB,CACvC,GAAI,CAACG,EAAWH,CAAG,EACjB,MAAO,GAGT,OADkBE,EAAaF,CAAG,EACf,CACjB,IAAK,MACL,IAAK,OACL,IAAK,OACL,IAAK,OACL,IAAK,MACL,IAAK,MACL,KAAK,OACH,MAAO,GACT,QACE,MAAO,EACX,CACF,CAEA,SAASE,EAAaF,EAA8B,CAClD,IAAMI,EAAQJ,EAAI,SAAS,MAAM,GAAG,EACpC,GAAI,EAAAI,EAAM,QAAU,GAGpB,OAAOA,EAAMA,EAAM,OAAS,CAAC,CAC/B,CAEO,SAASD,EAAWH,EAAmB,CAC5C,OAAOA,EAAI,SAAS,SAAS,UAAU,CACzC","names":["optimize","image","width","height","format","quality","fit","t","e","isFrameable","canExtractFrame","canBeResized","params","isVideo","url","extension","getExtension","isSeadnURL","split"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opensea/seadn",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Javascript SDK to work with SeaDN",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "OpenSea Developers",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"typecheck": "tsc"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@arethetypeswrong/cli": "0.15.
|
|
23
|
-
"tsup": "8.
|
|
24
|
-
"typescript": "5.5.
|
|
22
|
+
"@arethetypeswrong/cli": "0.15.4",
|
|
23
|
+
"tsup": "8.2.4",
|
|
24
|
+
"typescript": "5.5.4",
|
|
25
25
|
"vitest": "1.6.0"
|
|
26
26
|
}
|
|
27
27
|
}
|
package/src/sdk.spec.ts
CHANGED
|
@@ -88,6 +88,26 @@ test.each([
|
|
|
88
88
|
{ height: 100, width: 100, format: "avif" } satisfies MediaParams,
|
|
89
89
|
"https://xyz.com/bored-ape.png",
|
|
90
90
|
],
|
|
91
|
+
[
|
|
92
|
+
"https://i2.seadn.io/bored-ape",
|
|
93
|
+
{ t: 0.1 } satisfies MediaParams,
|
|
94
|
+
"https://i2.seadn.io/bored-ape",
|
|
95
|
+
],
|
|
96
|
+
[
|
|
97
|
+
"https://i2.seadn.io/bored-ape.mp4",
|
|
98
|
+
{ t: 0.1, height: 50 } satisfies MediaParams,
|
|
99
|
+
"https://i2.seadn.io/bored-ape.mp4?h=50&t=0.1",
|
|
100
|
+
],
|
|
101
|
+
[
|
|
102
|
+
"https://i2.seadn.io/bored-ape.gif",
|
|
103
|
+
{ t: 0.1 } satisfies MediaParams,
|
|
104
|
+
"https://i2.seadn.io/bored-ape.gif",
|
|
105
|
+
],
|
|
106
|
+
[
|
|
107
|
+
"https://i2.seadn.io/bored-ape.mp4",
|
|
108
|
+
{ width: 50, height: 50 } satisfies MediaParams,
|
|
109
|
+
"https://i2.seadn.io/bored-ape.mp4",
|
|
110
|
+
],
|
|
91
111
|
])("resizeImage(%o, %o) -> %o", (url, resizeParams, expected) => {
|
|
92
112
|
expect(optimize(url as string, resizeParams)).toEqual(expected);
|
|
93
113
|
});
|
package/src/sdk.ts
CHANGED
|
@@ -7,11 +7,13 @@ export type MediaParams = {
|
|
|
7
7
|
format?: MediaFormat;
|
|
8
8
|
quality?: number | `${number}`;
|
|
9
9
|
fit?: MediaFit;
|
|
10
|
+
// Frame extraction time in seconds. Only applicable for videos
|
|
11
|
+
t?: number;
|
|
10
12
|
};
|
|
11
13
|
|
|
12
14
|
export function optimize(
|
|
13
15
|
image: string | URL,
|
|
14
|
-
{ width, height, format, quality, fit }: MediaParams,
|
|
16
|
+
{ width, height, format, quality, fit, t }: MediaParams,
|
|
15
17
|
): string {
|
|
16
18
|
try {
|
|
17
19
|
if (typeof image === "string") {
|
|
@@ -25,7 +27,8 @@ export function optimize(
|
|
|
25
27
|
return image;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
const isFrameable = canExtractFrame(image);
|
|
31
|
+
if (!canBeResized(image) && !isFrameable) {
|
|
29
32
|
return image.toString();
|
|
30
33
|
}
|
|
31
34
|
|
|
@@ -48,22 +51,32 @@ export function optimize(
|
|
|
48
51
|
if (fit !== undefined) {
|
|
49
52
|
params.set("fit", fit);
|
|
50
53
|
}
|
|
54
|
+
if (t !== undefined) {
|
|
55
|
+
if (isFrameable) {
|
|
56
|
+
params.set("t", String(t));
|
|
57
|
+
}
|
|
58
|
+
} else if (isVideo(image)) {
|
|
59
|
+
return image.toString();
|
|
60
|
+
}
|
|
51
61
|
|
|
52
62
|
image.search = params.toString();
|
|
53
63
|
return image.toString();
|
|
54
64
|
}
|
|
55
65
|
|
|
66
|
+
function isVideo(url: URL): boolean {
|
|
67
|
+
const extension = getExtension(url);
|
|
68
|
+
return extension === "mp4" || extension === "mov";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function canExtractFrame(url: URL): boolean {
|
|
72
|
+
return isVideo(url);
|
|
73
|
+
}
|
|
74
|
+
|
|
56
75
|
function canBeResized(url: URL): boolean {
|
|
57
76
|
if (!isSeadnURL(url)) {
|
|
58
77
|
return false;
|
|
59
78
|
}
|
|
60
|
-
|
|
61
|
-
const split = url.pathname.split(".");
|
|
62
|
-
if (split.length <= 1) {
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const extension = split[split.length - 1];
|
|
79
|
+
const extension = getExtension(url);
|
|
67
80
|
switch (extension) {
|
|
68
81
|
case "png":
|
|
69
82
|
case "jpeg":
|
|
@@ -78,6 +91,14 @@ function canBeResized(url: URL): boolean {
|
|
|
78
91
|
}
|
|
79
92
|
}
|
|
80
93
|
|
|
94
|
+
function getExtension(url: URL): string | undefined {
|
|
95
|
+
const split = url.pathname.split(".");
|
|
96
|
+
if (split.length <= 1) {
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
return split[split.length - 1];
|
|
100
|
+
}
|
|
101
|
+
|
|
81
102
|
export function isSeadnURL(url: URL): boolean {
|
|
82
103
|
return url.hostname.endsWith("seadn.io");
|
|
83
104
|
}
|