@@ -62,6 +62,7 @@ if(domain === 'puter.localhost'){
62
62
static_hosting_domain = 'site.puter.localhost' ;
63
63
}
64
64
65
+ // port
65
66
if ( URLParams . has ( 'puter.port' ) && URLParams . get ( 'puter.port' ) ) {
66
67
static_hosting_domain = static_hosting_domain + `:` + URLParams . get ( 'puter.port' ) ;
67
68
}
@@ -81,7 +82,6 @@ if (URLParams.has('puter.port') && URLParams.get('puter.port')) {
81
82
$ ( document ) . ready ( function ( ) {
82
83
$ ( '#loading' ) . show ( ) ;
83
84
84
- // get dev profile
85
85
setTimeout ( async function ( ) {
86
86
puter . ui . onLaunchedWithItems ( async function ( items ) {
87
87
source_path = items [ 0 ] . path ;
@@ -95,6 +95,7 @@ $(document).ready(function () {
95
95
}
96
96
} )
97
97
98
+ // Get dev profile. This is only for puter.com for now as we don't have dev profiles in self-hosted Puter
98
99
if ( domain === 'puter.com' ) {
99
100
puter . apps . getDeveloperProfile ( async function ( dev_profile ) {
100
101
developer = dev_profile ;
@@ -119,7 +120,7 @@ $(document).ready(function () {
119
120
}
120
121
} )
121
122
}
122
- // get apps
123
+ // Get apps
123
124
puter . apps . list ( ) . then ( ( resp ) => {
124
125
apps = resp ;
125
126
@@ -176,16 +177,16 @@ $(document).on('click', '.tab-btn', function (e) {
176
177
$ ( this ) . addClass ( 'active' ) ;
177
178
$ ( 'section[data-tab="' + $ ( this ) . attr ( 'data-tab' ) + '"]' ) . show ( ) ;
178
179
179
- // ------------------------------
180
+ // ---------------------------------------------------------------
180
181
// Apps tab
181
- // ------------------------------
182
+ // ---------------------------------------------------------------
182
183
if ( $ ( this ) . attr ( 'data-tab' ) === 'apps' ) {
183
184
refresh_app_list ( ) ;
184
185
activeTab = 'apps' ;
185
186
}
186
- // ------------------------------
187
+ // ---------------------------------------------------------------
187
188
// Payout Method tab
188
- // ------------------------------
189
+ // ---------------------------------------------------------------
189
190
else if ( $ ( this ) . attr ( 'data-tab' ) === 'payout-method' ) {
190
191
activeTab = 'payout-method' ;
191
192
$ ( '#loading' ) . show ( ) ;
@@ -318,6 +319,7 @@ async function create_app(title, source_path = null, items = null) {
318
319
} )
319
320
}
320
321
322
+
321
323
$ ( document ) . on ( 'click' , '.deploy-btn' , function ( e ) {
322
324
deploy ( currently_editing_app , dropped_items ) ;
323
325
} )
@@ -856,8 +858,6 @@ $('#earn-money::backdrop').click(async function (e) {
856
858
puter . kv . set ( 'earn-money-c2a-closed' , 'true' )
857
859
} )
858
860
859
-
860
-
861
861
$ ( document ) . on ( 'click' , '.edit-app-open-app-btn' , async function ( e ) {
862
862
puter . ui . launchApp ( $ ( this ) . attr ( 'data-app-name' ) )
863
863
} )
@@ -983,8 +983,10 @@ $(document).on('click', '#edit-app-icon', async function (e) {
983
983
let image = reader . result ;
984
984
// Get file extension
985
985
let fileExtension = res2 . name . split ( '.' ) . pop ( ) ;
986
+
986
987
// Get MIME type
987
988
let mimeType = getMimeType ( fileExtension ) ;
989
+
988
990
// Replace MIME type in the data URL
989
991
image = image . replace ( 'data:application/octet-stream;base64' , `data:image/${ mimeType } ;base64` ) ;
990
992
@@ -1066,10 +1068,7 @@ function generate_app_card(app) {
1066
1068
h += `</td>` ;
1067
1069
1068
1070
h += `<td style="vertical-align:middle; min-width:200px;">` ;
1069
- // // Open App
1070
- // h += `<button class="open-app-btn button button-small" data-app-name="${html_encode(app.name)}">Open App</button>`;
1071
- // // Settings
1072
- // h += `<span class="edit-app" data-app-name="${html_encode(app.name)}" data-app-title="${html_encode(app.title)}" data-app-uid="${html_encode(app.uid)}"><img src="./img/settings.svg"></span>`;
1071
+
1073
1072
// "Approved for incentive program"
1074
1073
if ( app . approved_for_incentive_program )
1075
1074
h += `<span style="float:right;
@@ -1084,7 +1083,6 @@ function generate_app_card(app) {
1084
1083
return h ;
1085
1084
}
1086
1085
1087
-
1088
1086
/**
1089
1087
* Formats a binary-byte integer into the human-readable form with units.
1090
1088
*
@@ -1098,6 +1096,9 @@ window.byte_format = (bytes) => {
1098
1096
return Math . round ( bytes / Math . pow ( 1024 , i ) , 2 ) + ' ' + sizes [ i ] ;
1099
1097
} ;
1100
1098
1099
+ /**
1100
+ * check if a string is a valid email address
1101
+ */
1101
1102
function validateEmail ( email ) {
1102
1103
var re = / \S + @ \S + \. \S + / ;
1103
1104
return re . test ( email ) ;
@@ -1852,19 +1853,28 @@ $(document).on('change', '.select-all-apps', function (e) {
1852
1853
}
1853
1854
} )
1854
1855
1855
- // Function to map file extensions to MIME types
1856
+ /**
1857
+ * Get the MIME type for a given file extension.
1858
+ *
1859
+ * @param {string } extension - The file extension (with or without leading dot).
1860
+ * @returns {string } The corresponding MIME type, or 'application/octet-stream' if not found.
1861
+ */
1856
1862
function getMimeType ( extension ) {
1857
1863
const mimeTypes = {
1858
- jpg : 'jpeg' ,
1859
- jpeg : 'jpeg' ,
1860
- png : 'png' ,
1861
- gif : 'gif' ,
1862
- bmp : 'bmp' ,
1863
- webp : 'webp' ,
1864
- svg : 'svg+xml' ,
1865
- tiff : 'tiff' ,
1866
- ico : 'vnd.microsoft. icon'
1864
+ jpg : 'image/ jpeg' ,
1865
+ jpeg : 'image/ jpeg' ,
1866
+ png : 'image/ png' ,
1867
+ gif : 'image/ gif' ,
1868
+ bmp : 'image/ bmp' ,
1869
+ webp : 'image/ webp' ,
1870
+ svg : 'image/ svg+xml' ,
1871
+ tiff : 'image/ tiff' ,
1872
+ ico : 'image/x- icon'
1867
1873
} ;
1868
1874
1869
- return mimeTypes [ extension . toLowerCase ( ) ] || 'octet-stream' ;
1875
+ // Remove leading dot if present and convert to lowercase
1876
+ const cleanExtension = extension . replace ( / ^ \. / , '' ) . toLowerCase ( ) ;
1877
+
1878
+ // Return the MIME type if found, otherwise return 'application/octet-stream'
1879
+ return mimeTypes [ cleanExtension ] || 'application/octet-stream' ;
1870
1880
}
0 commit comments