@exezt-/webamp 1.5.0-0x4 → 1.5.0-0x5

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.
@@ -10084,8 +10084,18 @@ function selectAll() {
10084
10084
 
10085
10085
  class webamp_telegram_WinampTelegramCustomHandler {
10086
10086
  constructor() {
10087
+ defineProperty_default()(this, "webamp", void 0);
10088
+
10089
+ defineProperty_default()(this, "telegram", void 0);
10090
+
10091
+ defineProperty_default()(this, "initializeTelegramWebAppEvents", () => {
10092
+ this.telegram.offEvent("deactivated", () => {
10093
+ this.updateAppState();
10094
+ });
10095
+ });
10096
+
10087
10097
  defineProperty_default()(this, "updateAppState", () => {
10088
- localStorage.setItem('app-state', JSON.stringify(window.__webamp.store.getState()));
10098
+ localStorage.setItem("app-state", JSON.stringify(window.__webamp.store.getState()));
10089
10099
  });
10090
10100
 
10091
10101
  defineProperty_default()(this, "getFiles", async ln => {
@@ -10094,22 +10104,31 @@ class webamp_telegram_WinampTelegramCustomHandler {
10094
10104
  x.open('get', `https://cloud-api.yandex.net/v1/disk/public/resources?public_key=${link}`, true);
10095
10105
  x.setRequestHeader('Accept', 'application/json');
10096
10106
  x.setRequestHeader('Content-Type', 'application/json');
10097
- x.setRequestHeader('Access-Control-Allow-Origin', 'no-cors');
10098
10107
  x.send();
10099
10108
 
10100
10109
  x.onload = async () => {
10101
10110
  if (x.status === 200) {
10102
10111
  var _JSON$parse;
10103
10112
 
10104
- const playlistName = JSON.parse(x.responseText).name;
10105
10113
  const data = (_JSON$parse = JSON.parse(x.responseText)) === null || _JSON$parse === void 0 ? void 0 : _JSON$parse._embedded.items;
10106
10114
  let i = 0;
10107
10115
  this.saveLastPlaylist(ln);
10108
10116
 
10109
10117
  for (const item of data) {
10110
- if (item.size > 0x1400000) {// size too large
10118
+ if (item.size > 0x1400000) {
10119
+ console.info(`File ${item.name} can't be loaded due oversize`);
10111
10120
  } else {
10112
- await fetch(item.file).then(resp => fetch(resp.url)).then(res => {
10121
+ await fetch(item.file, {
10122
+ headers: [['Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'], ['Content-Type', 'application/octet-stream']]
10123
+ }).then(response => response).then(resp => fetch(resp.url)).then(async response => {
10124
+ if (response.status === 302) {
10125
+ return await fetch(response.headers.get('Location'), {
10126
+ headers: [['Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'], ['Content-Type', 'application/octet-stream']]
10127
+ });
10128
+ } else {
10129
+ return response;
10130
+ }
10131
+ }).then(res => {
10113
10132
  var _res$body;
10114
10133
 
10115
10134
  console.log(res);
@@ -10158,6 +10177,10 @@ class webamp_telegram_WinampTelegramCustomHandler {
10158
10177
  };
10159
10178
  });
10160
10179
 
10180
+ defineProperty_default()(this, "saveLastPlaylist", playlistLink => {
10181
+ document.cookie = `lastlist=${playlistLink}; path=/;`;
10182
+ });
10183
+
10161
10184
  defineProperty_default()(this, "getCookie", name => {
10162
10185
  const regex = new RegExp(`(^| )${name}=([^;]+)`);
10163
10186
  const match = document.cookie.match(regex);
@@ -10211,44 +10234,58 @@ class webamp_telegram_WinampTelegramCustomHandler {
10211
10234
  i++;
10212
10235
  }
10213
10236
 
10214
- if (window.__webamp.store.getState().media.shuffle !== opts.media.shuffle) window.__webamp.store.dispatch({
10215
- type: "TOGGLE_SHUFFLE"
10216
- });
10217
- if (window.__webamp.store.getState().media.repeat !== opts.media.repeat) window.__webamp.store.dispatch({
10218
- type: "TOGGLE_REPEAT"
10219
- });
10237
+ if (window.__webamp.store.getState().media.shuffle !== opts.media.shuffle) {
10238
+ window.__webamp.store.dispatch({
10239
+ type: "TOGGLE_SHUFFLE"
10240
+ });
10241
+ }
10242
+
10243
+ if (window.__webamp.store.getState().media.repeat !== opts.media.repeat) {
10244
+ window.__webamp.store.dispatch({
10245
+ type: "TOGGLE_REPEAT"
10246
+ });
10247
+ }
10220
10248
  });
10221
10249
 
10222
- let lastList = this.getCookie('lastlist');
10250
+ const lastList = this.getCookie('lastlist');
10223
10251
 
10224
10252
  if (typeof lastList !== "undefined") {
10225
- this.getFiles(lastList).catch(err => 0x0);
10253
+ this.getFiles(lastList);
10226
10254
  }
10255
+ }
10227
10256
 
10228
- setTimeout(() => {
10229
- if (typeof localStorage.getItem('app-state') !== "undefined") this.loadOptions(JSON.parse(localStorage.getItem('app-state')));
10257
+ initialize() {
10258
+ var _window, _window$Telegram, _window2, _window2$Telegram;
10230
10259
 
10231
- window.__webamp.onTrackDidChange(() => {
10232
- this.updateAppState();
10233
- });
10260
+ // @ts-ignore | because no global var telegram avail in project types
10261
+ this.telegram = (_window = window) === null || _window === void 0 ? void 0 : (_window$Telegram = _window.Telegram) === null || _window$Telegram === void 0 ? void 0 : _window$Telegram.WebApp;
10234
10262
 
10235
- window.__webamp.onWillClose(() => {
10236
- this.updateAppState();
10237
- });
10263
+ if (!window.__webamp) {
10264
+ throw new Error("Webamp __webamp is undefined!!");
10265
+ } // @ts-ignore | because no global var telegram avail in project types
10238
10266
 
10239
- window.__webamp.store.dispatch({
10240
- type: "ENABLE_MILKDROP",
10241
- open: false
10242
- });
10243
- }, 2000);
10244
- }
10245
10267
 
10246
- saveLastPlaylist(playlistName) {
10247
- document.cookie = `lastlist=${playlistName}; path=/;`;
10268
+ if (!((_window2 = window) !== null && _window2 !== void 0 && (_window2$Telegram = _window2.Telegram) !== null && _window2$Telegram !== void 0 && _window2$Telegram.WebApp)) {
10269
+ console.error("Telegram is undefined!! Skipping Telegram.WebApp event handler...");
10270
+ }
10271
+
10272
+ if (typeof localStorage.getItem('app-state') !== "undefined") this.loadOptions(JSON.parse(localStorage.getItem('app-state')));
10273
+
10274
+ window.__webamp.onTrackDidChange(() => {
10275
+ this.updateAppState();
10276
+ });
10277
+
10278
+ window.__webamp.onWillClose(() => {
10279
+ this.updateAppState();
10280
+ });
10281
+
10282
+ window.__webamp.store.dispatch({
10283
+ type: "ENABLE_MILKDROP",
10284
+ open: false
10285
+ });
10248
10286
  }
10249
10287
 
10250
10288
  }
10251
- new webamp_telegram_WinampTelegramCustomHandler();
10252
10289
  // CONCATENATED MODULE: ./js/actionCreators/files.ts
10253
10290
 
10254
10291