chore: tidy things up and fix typos

This commit is contained in:
LuanRT
2022-07-06 23:47:38 -03:00
parent 021a7fd97a
commit 9c97434e5e
5 changed files with 21 additions and 24 deletions

View File

@@ -1,4 +1,5 @@
'use strict';
const { openDB } = require('idb');
class BrowserCache {
@@ -11,7 +12,6 @@ class BrowserCache {
}
/**
*
* @param {string} key
* @returns {Promise<ArrayBuffer>}
*/
@@ -21,7 +21,6 @@ class BrowserCache {
}
/**
*
* @param {string} key
* @param {ArrayBuffer} data
* @returns {Promise<void>}
@@ -31,7 +30,6 @@ class BrowserCache {
}
/**
*
* @param {string} key
* @returns {Promise<boolean>}
*/
@@ -41,7 +39,6 @@ class BrowserCache {
}
/**
*
* @param {string} key
* @returns {Promise<void>}
*/

View File

@@ -1,12 +1,9 @@
'use strict';
const fs = require('fs');
class NodeCache {
constructor() {
}
/**
*
* @param {string} key
* @returns {Promise<ArrayBuffer>}
*/
@@ -15,7 +12,6 @@ class NodeCache {
}
/**
*
* @param {string} key
* @param {ArrayBuffer} data
* @returns {Promise<void>}
@@ -23,19 +19,21 @@ class NodeCache {
async write(key, data) {
// Make sure the directory exists
const parts = key.split('/').slice(0, -1);
let current = '';
for (let i = 0; i < parts.length; i++) {
current += `${parts[i]}/`;
for (const part of parts) {
current += `${part}/`;
if (!(await this.exists(current))) {
await fs.promises.mkdir(current);
}
}
return await fs.promises.writeFile(key, data);
}
/**
*
* @param {string} key
* @returns {Promise<boolean>}
*/
@@ -44,7 +42,6 @@ class NodeCache {
}
/**
*
* @param {string} key
* @returns {Promise<void>}
*/

View File

@@ -1,4 +1,5 @@
'use strict';
const glob = require('glob');
const fs = require('fs');

View File

@@ -1,6 +1,7 @@
'use strict';
global.XMLHttpRequest = class extends require('xhr2') {
// This is for browser-like environments not nessacarily a browser
// So disabling this is okay, sort of
// This is for browser-like environments not necessarily a browser.
// So disabling this is okay, sort of.
_restrictedHeaders = {};
};

View File

@@ -1,17 +1,18 @@
'use strict';
const Fs = require('fs');
const Innertube = require('../../build/node');
const Innertube = require('../../build/browser');
const { default: NToken } = require('../../lib/deciphers/NToken');
const { default: Signature} = require('../../lib/deciphers/Signature');
const Constants = require('../constants');
// NOTE:
// these tests disable the restricted headers in XMLHttpRequest
// so techinically these tests are not 100% accurate, so they
// really represent a browser-like environment and not necessarily a browser
// i.e. electron, where you could disable this restriction
/**
* Note:
* These tests disable the restricted headers in XMLHttpRequest.
* So technically, they are not 100% accurate and represent browser-like
* environments such as Electron.
*/
describe('YouTube.js Tests', () => {
beforeAll(async () => {
this.session = await new Innertube();
@@ -83,7 +84,7 @@ describe('YouTube.js Tests', () => {
});
/*
// After a lot of testing, I don't think it is possible to download videos in browser
// After a lot of testing, I don't think it is possible to download videos in a browser.
it('Should download video', async () => {
const result = await download(Constants.VIDEOS[1].ID, this.session);
expect(result).toBeTruthy();