Skip to content

Commit

Permalink
test(cat-voices): separating utils in files
Browse files Browse the repository at this point in the history
  • Loading branch information
emiride committed Oct 28, 2024
1 parent 7c7e554 commit 0bbeb68
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
APP_URL=http://app:80
WALLET1_SEED_WORD=stomach,horn,rail,afraid,flip,also,abandon,speed,chaos,daring,soon,soft,okay,online,benefit
APP_URL=http://localhost:8000
WALLET1_SEED_WORD=stomach,horn,rail,afraid,flip,also,abandon,speed,chaos,daring,soon,soft,okay,online,benefit
WALLET1_USERNAME=test123
WALLET1_PASSWORD=test12345678@
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export { getSeedPhrase };

const downloadExtension = async (extID: string): Promise<string> => {
const unzip = require("unzip-crx-3");
const url = `https://clients2.google.com/service/update2/crx?response=redirect&os=win&arch=x64&os_arch=x86_64&nacl_arch=x86-64&prod=chromiumcrx&prodchannel=beta&prodversion=79.0.3945.53&lang=ru&acceptformat=crx3&x=id%3D${extID}%26installsource%3Dondemand%26uc`;
const url = `https://clients2.google.com/service/update2/crx?response=redirect&os=win&arch=x64&os_arch=x86_64&nacl_arch=x86-64&prod=chromiumcrx&prodchannel=stable&prodversion=latest&lang=en&acceptformat=crx3&x=id%3D${extID}%26installsource%3Dondemand%26uc`;
const downloadPath = path.resolve(__dirname, 'extensions');
await fs.mkdir(downloadPath, { recursive: true });
const filePath = path.join(downloadPath, extID + '.crx');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
interface PlatformInfo {
os: string;
arch: string;
nacl_arch: string;
}

class ExtensionDownloader {
public getCrxUrl(extensionIDOrUrl: string | ExtensionID): string {
let extensionID: string;

if (typeof extensionIDOrUrl === 'string') {
const idMatch = this.getExtensionID(extensionIDOrUrl);
extensionID = idMatch ? idMatch : extensionIDOrUrl;
} else {
extensionID = extensionIDOrUrl;
}

if (!/^[a-z]{32}$/.test(extensionID)) {
return extensionIDOrUrl;
}

const platformInfo = this.getPlatformInfo();
const productId = this.isChromeNotChromium() ? 'chromecrx' : 'chromiumcrx';
const productChannel = 'unknown';
let productVersion = '9999.0.9999.0';

const crVersion = /Chrome\/((\d+)\.0\.(\d+)\.\d+)/.exec(navigator.userAgent);
if (crVersion && +crVersion[2] >= 31 && +crVersion[3] >= 1609) {
productVersion = crVersion[1];
}

let url = 'https://clients2.google.com/service/update2/crx?response=redirect';
url += '&os=' + platformInfo.os;
url += '&arch=' + platformInfo.arch;
url += '&os_arch=' + platformInfo.os_arch;
url += '&nacl_arch=' + platformInfo.nacl_arch;
url += '&prod=' + productId;
url += '&prodchannel=' + productChannel;
url += '&prodversion=' + productVersion;
url += '&x=id%3D' + extensionID + '%26installsource%3Dondemand%26uc';
return url;
}

private getExtensionID(url: string): string | null {
const pattern = /chrome\.google\.com\/webstore\/detail\/[^\/]+\/([a-z]{32})/i;
const match = pattern.exec(url);
return match ? match[1] : null;
}

private isChromeNotChromium(): boolean {
return (
navigator.userAgent.includes('Chrome') &&
!navigator.userAgent.includes('Chromium')
);
}

private getPlatformInfo(): PlatformInfo & { os_arch: string } {
const platform = navigator.platform.toLowerCase();
let os = 'win';
if (platform.startsWith('mac')) {
os = 'mac';
} else if (platform.startsWith('linux')) {
os = 'linux';
} else if (platform.startsWith('cros')) {
os = 'cros';
}

const is64Bit = /x86_64|Win64|WOW64|AMD64/.test(navigator.userAgent);
const arch = is64Bit ? 'x64' : 'x86';
const os_arch = is64Bit ? 'x86_64' : 'x86';
const naclArch = is64Bit ? 'x86-64' : 'x86-32';

return { os, arch, os_arch, nacl_arch: naclArch };
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export interface Extension {
Name: string,
Id: string
}

export enum ExtensionName {
Lace = 'Lace',
Typhon = 'Typhon'
}

const extensions: Extension[] = [
{
Name: ExtensionName.Lace,
Id: 'lace-id'
},
{
Name: ExtensionName.Typhon,
Id: 'typhon-id'
}
];

0 comments on commit 0bbeb68

Please sign in to comment.