Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function getAwaToken(
account: DestinyAccount,
action: AwaType,
item?: D2Item
): Promise {
if (!awaCache) {
// load from cache first time
awaCache = (await get('awa-tokens')) || {};
}
let info = awaCache[action];
if (!info || !tokenValid(info)) {
try {
// Note: Error messages should be handled by other components. This is just to tell them to check the app.
showNotification({
type: 'info',
title: t('AWA.ConfirmTitle'),
body: t('AWA.ConfirmDescription')
});
info = awaCache[action] = {
...(await requestAdvancedWriteActionToken(account, action, item)),
used: 0
};
async function openTerminalInNewPaneItem(
options: atom$WorkspaceOpenOptions & {
terminalInfo: TerminalInfo,
},
): Promise {
const existingPane = atom.workspace.paneForURI(TERMINAL_URI);
// TODO: The flow types are wrong. paneForURI returns a nullable pane
if (!existingPane) {
// eslint-disable-next-line nuclide-internal/atom-apis
return atom.workspace.open(TERMINAL_URI, options);
}
const [item, hasShownNux] = await Promise.all([
atom.workspace.createItemForURI(TERMINAL_URI, options),
AsyncStorage.get(MOVED_TERMINAL_NUX_SHOWN_KEY),
]);
existingPane.activateItem(item);
existingPane.activate();
if (!hasShownNux) {
invariant(item instanceof TerminalView);
showTooltipForPaneItem(item);
AsyncStorage.set(MOVED_TERMINAL_NUX_SHOWN_KEY, true);
}
return item;
}
get: function() {
return idbKeyval.get('DIM-data').then((value) => {
// Fall back to local storage as a migration aid
if (!value || _.isEmpty(value)) {
return JSON.parse(localStorage.getItem('DIM'));
}
return value;
});
},
const fetchInstrumentFromRemote = async (
instrument = DRUMS_NAME,
isDrums?: boolean
) => {
const instrumentId = getInstrumentIdByValue(instrument);
const { drums, tracks } = midiFontData;
if (isDrums && drums) {
return drums;
} else if (tracks[instrumentId]) {
return tracks[instrumentId];
}
if (isDrums) {
const _drums = await getInIDB(DRUMS_NAME);
if (drums) {
return _drums;
}
} else {
const track = await getInIDB(getIdbKey(instrumentId));
if (track) return track;
}
let url = !process.env.DEV
? `https://midifonts.s3.ap-south-1.amazonaws.com/${instrument}-mp3.js`
: `https://gleitz.github.io/midi-js-soundfonts/MusyngKite/${instrument}-mp3.js`;
if (isDrums) {
url =
"https://raw.githubusercontent.com/dave4mpls/midi-js-soundfonts-with-drums/gh-pages/drums-mp3.js";
}
.switchMap(() => AsyncStorage.get(NUX_ASYNC_STORAGE_KEY))
.filter(seen => !seen)
private loadManifestFromCache(version): IPromise {
if (alwaysLoadRemote) {
return $q.reject(new Error("Testing - always load remote"));
}
this.statusText = `${t('Manifest.Load')}...`;
const currentManifestVersion = localStorage.getItem(this.localStorageKey);
if (currentManifestVersion === version) {
return $q.when(idbKeyval.get(this.idbKey)).then((typedArray: Uint8Array) => {
if (!typedArray) {
throw new Error("Empty cached manifest file");
}
return typedArray;
});
} else {
ga('send', 'event', 'Manifest', 'Need New Manifest');
return $q.reject(new Error(`version mismatch: ${version} ${currentManifestVersion}`));
}
}
}
return new Promise(async (resolve) => {
const mergeInfo: MergeInformation = await get('deckdeckgo_redirect_info');
if (mergeInfo && mergeInfo.userId && mergeInfo.userToken) {
resolve();
return;
}
await set('deckdeckgo_redirect', this.redirect ? this.redirect : '/');
const observables = [];
observables.push(this.authService.watch().pipe(take(1)));
observables.push(this.userService.watch().pipe(take(1)));
observables.push(this.deckEditorService.watch().pipe(take(1)));
forkJoin(observables).subscribe(async ([authUser, user, deck]: [AuthUser, User, Deck]) => {
await set('deckdeckgo_redirect_info', {
deckId: deck ? deck.id : null,
const instrumentId = getInstrumentIdByValue(instrument);
const { drums, tracks } = midiFontData;
if (isDrums && drums) {
return drums;
} else if (tracks[instrumentId]) {
return tracks[instrumentId];
}
if (isDrums) {
const _drums = await getInIDB(DRUMS_NAME);
if (drums) {
return _drums;
}
} else {
const track = await getInIDB(getIdbKey(instrumentId));
if (track) return track;
}
let url = !process.env.DEV
? `https://midifonts.s3.ap-south-1.amazonaws.com/${instrument}-mp3.js`
: `https://gleitz.github.io/midi-js-soundfonts/MusyngKite/${instrument}-mp3.js`;
if (isDrums) {
url =
"https://raw.githubusercontent.com/dave4mpls/midi-js-soundfonts-with-drums/gh-pages/drums-mp3.js";
}
const response = await fetch(url);
const data = await response.text();
const result = midiJsToJson(data);
if (isDrums) {
public loadSoundFont = async (instrument = instruments[0].value) => {
let audio;
try {
audio = await getFromIDB(instrument);
if (!audio) audio = await this.fetchInstrumentFromRemote(instrument);
} catch (e) {
audio = await this.fetchInstrumentFromRemote(instrument);
}
const promises = Object.keys(audio).map(
key => new Promise(resolve => this.sampler.add(key, audio[key], resolve))
);
return Promise.all(promises);
};