vona-module-a-static 5.0.20 → 5.0.23

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.
@@ -0,0 +1,7 @@
1
+ import { Meta } from 'vona-module-a-meta';
2
+ import { BeanAssetBase } from 'vona-module-a-static';
3
+
4
+ export interface I<%=argv.beanNameCapitalize%>GetPath {}
5
+
6
+ @Meta()
7
+ export class Meta<%=argv.beanNameCapitalize%> extends BeanAssetBase<I<%=argv.beanNameCapitalize%>GetPath> {}
package/dist/index.js CHANGED
@@ -118,7 +118,7 @@ async function _getFullPathInner(ctx, dir, filename, options) {
118
118
  // trim prefix
119
119
  if (options.apiStaticPrefix !== '/') {
120
120
  const filePrefix = path.normalize(options.apiStaticPrefix.replace(/^\//, ''));
121
- if (filename.indexOf(filePrefix) !== 0) return;
121
+ if (filename.indexOf(filePrefix) !== 0) throw new Error(`invalid filename: ${filename}`);
122
122
  filename = filename.slice(filePrefix.length);
123
123
  }
124
124
  // check
@@ -128,13 +128,13 @@ async function _getFullPathInner(ctx, dir, filename, options) {
128
128
  if (wordFirst === 'public') {
129
129
  const fullPath = path.normalize(path.join(dir, parts.join(path.sep)));
130
130
  // files that can be accessd should be under options.dir
131
- if (fullPath.indexOf(dir) !== 0) return;
131
+ if (fullPath.indexOf(dir) !== 0) throw new Error(`unsafe filename: ${filename}`);
132
132
  return fullPath;
133
133
  }
134
134
  // static
135
135
  const moduleRelativeName = `${wordFirst}-${parts.shift()}`;
136
136
  const module = ctx.app.meta.modules[moduleRelativeName];
137
- if (!module) return;
137
+ if (!module) throw new Error(`invalid filename: ${filename}`);
138
138
  const fullPath = ctx.app.util.getAssetPathPhysical(moduleRelativeName, 'static', parts.join(path.sep));
139
139
  return fullPath;
140
140
  }
@@ -151,10 +151,16 @@ let ScopeModuleAStatic = (_dec = Scope(), _dec2 = BeanInfo({
151
151
 
152
152
  /** scope: end */
153
153
 
154
+ class BeanAssetBase extends BeanBase {
155
+ get(scene, assetPath) {
156
+ return this.app.util.getAssetPathPhysical(this[SymbolModuleBelong], scene, assetPath);
157
+ }
158
+ }
159
+
154
160
  class BeanStaticBase extends BeanBase {
155
161
  get(path) {
156
162
  return this.app.util.combineStaticPath(path, this[SymbolModuleBelong]);
157
163
  }
158
164
  }
159
165
 
160
- export { BeanStaticBase, EventResolvePath, MiddlewareSystemStatic, ScopeModuleAStatic, SymbolStaticGetFullPathInner };
166
+ export { BeanAssetBase, BeanStaticBase, EventResolvePath, MiddlewareSystemStatic, ScopeModuleAStatic, SymbolStaticGetFullPathInner };
@@ -0,0 +1,4 @@
1
+ import { BeanBase } from 'vona';
2
+ export declare class BeanAssetBase<IAssetGetPath> extends BeanBase {
3
+ get<K extends keyof IAssetGetPath, V extends IAssetGetPath[K]>(scene: K, assetPath: V): string;
4
+ }
@@ -1 +1,2 @@
1
+ export * from './beanAssetBase.ts';
1
2
  export * from './beanStaticBase.ts';
package/package.json CHANGED
@@ -1,14 +1,18 @@
1
1
  {
2
2
  "name": "vona-module-a-static",
3
3
  "type": "module",
4
- "version": "5.0.20",
4
+ "version": "5.0.23",
5
5
  "title": "a-static",
6
6
  "vonaModule": {
7
7
  "dependencies": {},
8
8
  "metas": {
9
9
  "static": {
10
10
  "scopeResource": true,
11
- "boilerplate": "cli/boilerplate"
11
+ "boilerplate": "cli/static/boilerplate"
12
+ },
13
+ "asset": {
14
+ "scopeResource": true,
15
+ "boilerplate": "cli/asset/boilerplate"
12
16
  }
13
17
  }
14
18
  },
@@ -28,9 +32,9 @@
28
32
  "./package.json": "./package.json"
29
33
  },
30
34
  "files": [
35
+ "assets",
31
36
  "cli",
32
- "dist",
33
- "static"
37
+ "dist"
34
38
  ],
35
39
  "dependencies": {
36
40
  "@cabloy/koa-static-cache": "^6.0.1",