@blocklet/launcher-util 2.1.67 → 2.1.69

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.
Files changed (2) hide show
  1. package/lib/util.js +38 -0
  2. package/package.json +2 -2
package/lib/util.js CHANGED
@@ -115,6 +115,41 @@ const getContinueLaunchURL = ({ baseURL, launch }) => {
115
115
  return '';
116
116
  };
117
117
 
118
+ const getBlockletMetaUrlFromQuery = (query) => {
119
+ // 兼容 meta_url 参数
120
+ const url = (query.get('blocklet_meta_url') || query.get('meta_url') || '').trim();
121
+ return decodeURIComponent(url);
122
+ };
123
+
124
+ const getRegistryUrlFromBlockletMetaUrl = (blockletMetaUrl) => {
125
+ try {
126
+ return blockletMetaUrl ? new URL(blockletMetaUrl).origin : '';
127
+ } catch (error) {
128
+ console.error('get registry url from blocklet meta url error:', error);
129
+ return '';
130
+ }
131
+ };
132
+
133
+ const formatRegistryLogoPath = (did, asset) => {
134
+ if (asset.startsWith('/assets')) {
135
+ return asset;
136
+ }
137
+
138
+ return `/assets/${did}/${asset}`;
139
+ };
140
+
141
+ const getBlockletLogoUrl = ({ did, baseUrl, logoPath }) => {
142
+ if (logoPath && logoPath.startsWith('http')) {
143
+ return logoPath;
144
+ }
145
+
146
+ if (baseUrl.startsWith('http') && logoPath) {
147
+ return joinURL(baseUrl, formatRegistryLogoPath(did, logoPath));
148
+ }
149
+
150
+ return '';
151
+ };
152
+
118
153
  module.exports = {
119
154
  formatPeriod,
120
155
  prettyDurationUnit,
@@ -128,4 +163,7 @@ module.exports = {
128
163
  getBlockletDisplayName,
129
164
  getBlockletAdminURL,
130
165
  getContinueLaunchURL,
166
+ getBlockletMetaUrlFromQuery,
167
+ getRegistryUrlFromBlockletMetaUrl,
168
+ getBlockletLogoUrl,
131
169
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/launcher-util",
3
- "version": "2.1.67",
3
+ "version": "2.1.69",
4
4
  "description": "Common constants",
5
5
  "keywords": [
6
6
  "constant"
@@ -46,5 +46,5 @@
46
46
  "devDependencies": {
47
47
  "jest": "^27.5.1"
48
48
  },
49
- "gitHead": "f69e1b1a19dda74a0402caf04e5d47602e2af10f"
49
+ "gitHead": "610aed556851444ba8516742d691a5e6a04d000c"
50
50
  }