u2a 2.0.0 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "u2a",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "URL to App - Turn any URL into a desktop application",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -6,7 +6,6 @@ const { getFavicon } = require('../utils/favicon');
6
6
  const { APPS_DIR, readDB, writeDB } = require('../utils/config');
7
7
  const Logger = require('../utils/logger');
8
8
  const os = require('os');
9
- const { isContext } = require('vm');
10
9
 
11
10
  const logger = new Logger('create');
12
11
 
@@ -331,7 +330,7 @@ async function createApp(url) {
331
330
  logger.info(`Creating application for ${url}`);
332
331
 
333
332
  try {
334
- url = normalizeUrl(url);
333
+ url = await normalizeUrl(url);
335
334
  const domain = getDomainName(url);
336
335
 
337
336
  const db = readDB();
@@ -10,7 +10,7 @@ const logger = new Logger('remove');
10
10
 
11
11
  async function removeApp(url) {
12
12
  try {
13
- const domain = getDomainName(normalizeUrl(url));
13
+ const domain = getDomainName(await normalizeUrl(url));
14
14
  const db = readDB();
15
15
 
16
16
  if (!db.hasOwnProperty(domain)) {
@@ -13,7 +13,7 @@ async function getFavicon(url) {
13
13
 
14
14
  try {
15
15
  const domain = getDomainName(url);
16
- const normalizedUrl = normalizeUrl(url);
16
+ const normalizedUrl = await normalizeUrl(url);
17
17
 
18
18
  const faviconUrl = `${normalizedUrl}/favicon.ico`;
19
19
  const iconResponse = await axios.get(faviconUrl, { responseType: 'arraybuffer' });
package/src/utils/url.js CHANGED
@@ -1,6 +1,13 @@
1
- function normalizeUrl(url) {
1
+ const axios = require('axios');
2
+
3
+ async function normalizeUrl(url) {
2
4
  if (!url.startsWith('http://') && !url.startsWith('https://')) {
3
- url = 'https://' + url;
5
+ try {
6
+ await axios.get('https://' + url);
7
+ url = 'https://' + url;
8
+ } catch (error) {
9
+ url = 'http://' + url;
10
+ }
4
11
  }
5
12
  return url;
6
13
  }
@@ -17,4 +24,4 @@ function getDomainName(url) {
17
24
  module.exports = {
18
25
  normalizeUrl,
19
26
  getDomainName
20
- };
27
+ };