adminforth 2.22.0-next.17 → 2.22.0-next.19

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.
@@ -13,6 +13,9 @@ import Handlebars from 'handlebars';
13
13
  import { promisify } from 'util';
14
14
  import { getVersion } from '../cli.js';
15
15
 
16
+ import { URL } from 'url'
17
+ import net from 'net'
18
+
16
19
  const execAsync = promisify(exec);
17
20
 
18
21
  function detectAdminforthVersion() {
@@ -159,6 +162,44 @@ function checkForExistingPackageJson(options) {
159
162
  }
160
163
  }
161
164
 
165
+ function checkIfDatabaseLocal(urlString) {
166
+ if (urlString.startsWith('sqlite')) {
167
+ return true;
168
+ }
169
+ try {
170
+ const url = new URL(urlString)
171
+
172
+ const host = url.hostname
173
+
174
+ if (!host) return false
175
+
176
+ // localhost
177
+ if (host === 'localhost') return true
178
+
179
+ // loopback ipv4
180
+ if (host === '127.0.0.1') return true
181
+
182
+ // loopback ipv6
183
+ if (host === '::1') return true
184
+
185
+ // private IP ranges
186
+ if (net.isIP(host)) {
187
+ if (
188
+ host.startsWith('10.') ||
189
+ host.startsWith('192.168.') ||
190
+ host.match(/^172\.(1[6-9]|2\d|3[0-1])\./)
191
+ ) {
192
+ return true
193
+ }
194
+ }
195
+
196
+
197
+ return false
198
+ } catch {
199
+ return false
200
+ }
201
+ }
202
+
162
203
  async function scaffoldProject(ctx, options, cwd) {
163
204
  const projectDir = path.join(cwd, options.appName);
164
205
  await fse.ensureDir(projectDir);
@@ -253,7 +294,7 @@ async function writeTemplateFiles(dirname, cwd, options) {
253
294
  {
254
295
  src: '.env.local.hbs',
255
296
  dest: '.env.local',
256
- data: { dbUrl, prismaDbUrl },
297
+ data: { dbUrl: checkIfDatabaseLocal(dbUrl) ? dbUrl : null, prismaDbUrl },
257
298
  },
258
299
  {
259
300
  src: '.env.prod.hbs',
@@ -269,8 +310,7 @@ async function writeTemplateFiles(dirname, cwd, options) {
269
310
  // We'll write .env using the same content as .env.sample
270
311
  src: '.env.local.hbs',
271
312
  dest: '.env',
272
- data: {},
273
- empty: true,
313
+ data: {dbUrl, prismaDbUrl},
274
314
  },
275
315
  {
276
316
  src: 'adminuser.ts.hbs',
@@ -598,4 +598,22 @@ export function generateMessageHtmlForRecordChange(changedFields: Record<string,
598
598
  const listHtml = items ? `<ul class="mt-2 list-disc list-inside">${items}</ul>` : '';
599
599
  const messageHtml = `<div>${escapeHtml(t('There are unsaved changes. Are you sure you want to leave this page?'))}${listHtml}</div>`;
600
600
  return messageHtml;
601
+ }
602
+
603
+ export function getTimeAgoString(date: Date): string {
604
+ const now = new Date();
605
+ const diffInSeconds = Math.floor((now.getTime() - date.getTime()) / 1000);
606
+
607
+ if (diffInSeconds < 60) {
608
+ return `${diffInSeconds} ${diffInSeconds === 1 ? 'second' : 'seconds'} ago`;
609
+ } else if (diffInSeconds < 3600) {
610
+ const minutes = Math.floor(diffInSeconds / 60);
611
+ return `${minutes} ${minutes === 1 ? 'minute' : 'minutes'} ago`;
612
+ } else if (diffInSeconds < 86400) {
613
+ const hours = Math.floor(diffInSeconds / 3600);
614
+ return `${hours} ${hours === 1 ? 'hour' : 'hours'} ago`;
615
+ } else {
616
+ const days = Math.floor(diffInSeconds / 86400);
617
+ return `${days} ${days === 1 ? 'day' : 'days'} ago`;
618
+ }
601
619
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adminforth",
3
- "version": "2.22.0-next.17",
3
+ "version": "2.22.0-next.19",
4
4
  "description": "OpenSource Vue3 powered forth-generation admin panel",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",