mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 02:57:34 +00:00
feat: allow filtering per model by a specific series (#595)
Co-authored-by: Jef LeCompte <jeffreylec@gmail.com>
This commit is contained in:
@@ -124,7 +124,7 @@ Here is a list of variables that you can use to customize your newly copied `.en
|
||||
| `PUSHOVER_PRIORITY` | Pushover message priority |
|
||||
| `SCREENSHOT` | Capture screenshot of page if a card is found | Default: `true` |
|
||||
| `SHOW_ONLY_BRANDS` | Filter to show specified brands | Comma separated, e.g.: `evga,zotac` |
|
||||
| `SHOW_ONLY_MODELS` | Filter to show specified models | Comma separated, e.g.: `founders edition,rog strix` |
|
||||
| `SHOW_ONLY_MODELS` | Filter to show specified models | Both supported formats are comma separated <br/><br/>1. Standard E.g.: `founders edition,rog strix` <br/><br/> 2. Advanced E.g: `MODEL:SERIES`, E.g: `founders edition:3090,rog strix` |
|
||||
| `SHOW_ONLY_SERIES` | Filter to show specified series | Comma separated, e.g.: `3080` |
|
||||
| `SLACK_CHANNEL` | Slack channel for posting | E.g.: `update`, no need for `#` |
|
||||
| `SLACK_TOKEN` | Slack API token | |
|
||||
|
||||
+7
-1
@@ -243,7 +243,13 @@ const store = {
|
||||
},
|
||||
microCenterLocation: envOrArray(process.env.MICROCENTER_LOCATION, ['web']),
|
||||
showOnlyBrands: envOrArray(process.env.SHOW_ONLY_BRANDS),
|
||||
showOnlyModels: envOrArray(process.env.SHOW_ONLY_MODELS),
|
||||
showOnlyModels: envOrArray(process.env.SHOW_ONLY_MODELS).map(entry => {
|
||||
const [name, series] = entry.match(/[^:]+/g) ?? [];
|
||||
return {
|
||||
name: envOrString(name),
|
||||
series: envOrString(series)
|
||||
};
|
||||
}),
|
||||
showOnlySeries: envOrArray(process.env.SHOW_ONLY_SERIES, ['3070', '3080', '3090']),
|
||||
stores: envOrArray(process.env.STORES, ['nvidia']).map(entry => {
|
||||
const [name, minPageSleep, maxPageSleep] = entry.match(/[^:]+/g) ?? [];
|
||||
|
||||
+11
-5
@@ -18,16 +18,22 @@ function filterBrand(brand: Link['brand']): boolean {
|
||||
* Returns true if the model should be checked for stock
|
||||
*
|
||||
* @param model The model of the GPU
|
||||
* @param series The series of the GPU
|
||||
*/
|
||||
function filterModel(model: Link['model']): boolean {
|
||||
function filterModel(model: Link['model'], series: Link['series']): boolean {
|
||||
if (config.store.showOnlyModels.length === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const sanitizedModel = model.replace(/\s/g, '');
|
||||
for (const configModel of config.store.showOnlyModels) {
|
||||
const sanitizedConfigModel = configModel.replace(/\s/g, '');
|
||||
if (sanitizedModel === sanitizedConfigModel) {
|
||||
const sanitizedSeries = series.replace(/\s/g, '');
|
||||
for (const configModelEntry of config.store.showOnlyModels) {
|
||||
const sanitizedConfigModel = configModelEntry.name.replace(/\s/g, '');
|
||||
const sanitizedConfigSeries = configModelEntry.series.replace(/\s/g, '');
|
||||
if (sanitizedConfigSeries ?
|
||||
sanitizedSeries === sanitizedConfigSeries && sanitizedModel === sanitizedConfigModel :
|
||||
sanitizedModel === sanitizedConfigModel
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -56,7 +62,7 @@ export function filterSeries(series: Link['series']): boolean {
|
||||
export function filterStoreLink(link: Link): boolean {
|
||||
return (
|
||||
filterBrand(link.brand) &&
|
||||
filterModel(link.model) &&
|
||||
filterModel(link.model, link.series) &&
|
||||
filterSeries(link.series)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -115,7 +115,9 @@ if (config.store.showOnlyBrands.length > 0) {
|
||||
}
|
||||
|
||||
if (config.store.showOnlyModels.length > 0) {
|
||||
logger.info(`ℹ selected models: ${config.store.showOnlyModels.join(', ')}`);
|
||||
logger.info(`ℹ selected models: ${config.store.showOnlyModels.map(entry => {
|
||||
return entry.series ? entry.name + ' (' + entry.series + ')' : entry.name;
|
||||
}).join(', ')}`);
|
||||
}
|
||||
|
||||
if (config.store.showOnlySeries.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user