Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
1.1 kB
4
Indexable
Never
async parseShopeeUrl(url) {
        const parsed = queryString.parseUrl(url);
        let match, params, type;
        if ((match = /shop\/(\d*)/.exec(parsed.url)) !== null) {
            type = 'shop';
            params = {id: match[1], ...parsed.query};
        } else if (parsed.url.endsWith('search') || parsed.url.endsWith('search/')) {
            type = 'search';

            params = parsed.query;
        } else if ((match = /cat\.(\d*)/.exec(parsed.url)) !== null) {
            type = 'cat';
            params = {id: match[1], ...parsed.query};
            if ((match = /cat\.\d*.(\d*)/.exec(parsed.url)) && match[1]) {
                params.id = match[1];
            }
        } else if ((match = /col\.(\d*)/.exec(parsed.url)) !== null) {
            type = 'col';
            params = {id: match[1], ...parsed.query};
        } else {
            let username = parsed.url.split("/").pop();
            let res = await ShopeeServices.idByUserName(username);
            type = 'shop';
            params = {id: res.data.id, ...parsed.query};
        }

        return {type, params};
    }