File tree 3 files changed +40
-6
lines changed
3 files changed +40
-6
lines changed Original file line number Diff line number Diff line change 1
1
import { promises as fsp } from "node:fs" ;
2
2
import { extname } from "pathe" ;
3
+ import mime from "mime" ;
3
4
import type { Plugin } from "rollup" ;
4
5
5
6
export interface RawOptions {
@@ -18,15 +19,9 @@ export function raw(opts: RawOptions = {}): Plugin {
18
19
".css" ,
19
20
".htm" ,
20
21
".html" ,
21
- ".json" ,
22
- ".json5" ,
23
- ".csv" ,
24
22
...( opts . extensions || [ ] ) ,
25
23
] ) ;
26
24
27
- // TODO: use ext=>mime
28
- const isBinary = ( id ) => ! extensions . has ( extname ( id ) ) ;
29
-
30
25
return {
31
26
name : "raw" ,
32
27
resolveId ( id ) {
@@ -79,6 +74,17 @@ export function raw(opts: RawOptions = {}): Plugin {
79
74
} ;
80
75
}
81
76
77
+ function isBinary ( id : string ) {
78
+ const idMime = mime . getType ( id ) || "" ;
79
+ if ( idMime . startsWith ( "text/" ) ) {
80
+ return false ;
81
+ }
82
+ if ( / a p p l i c a t i o n \/ ( j s o n | x m l | y a m l ) / . test ( idMime ) ) {
83
+ return false ;
84
+ }
85
+ return true ;
86
+ }
87
+
82
88
function getHelpers ( ) {
83
89
const js = String . raw ;
84
90
return js `
Original file line number Diff line number Diff line change
1
+ {
2
+ "foo" : " bar"
3
+ }
Original file line number Diff line number Diff line change
1
+ export default eventHandler ( async ( event ) => {
2
+ const serverAssets = useStorage ( "assets/server" ) ;
3
+
4
+ const keys = await serverAssets . getKeys ( ) ;
5
+ const items = await Promise . all (
6
+ keys . map ( async ( key ) => {
7
+ return {
8
+ key,
9
+ meta : await serverAssets . getMeta ( key ) ,
10
+ data : await serverAssets . getItem ( key ) . then ( ( r ) =>
11
+ // prettier-ignore
12
+ typeof r === "string" ? r . slice ( 0 , 32 ) : ( isPureObject ( r ) ? r : `<data>` )
13
+ ) ,
14
+ } ;
15
+ } )
16
+ ) ;
17
+
18
+ return items ;
19
+ } ) ;
20
+
21
+ function isPureObject ( value ) {
22
+ return (
23
+ value !== null && typeof value === "object" && value . constructor === Object
24
+ ) ;
25
+ }
You can’t perform that action at this time.
0 commit comments