DeFactOfficial commited on
Commit
bdc1e12
1 Parent(s): d9ec121

Update retrievers/community_diffusion_models.js

Browse files
retrievers/community_diffusion_models.js CHANGED
@@ -1,4 +1,3 @@
1
- const express = require('express');
2
  const fs = require('fs');
3
  // Read and Parse JSON Data
4
  const data = JSON.parse(fs.readFileSync('diffusers-unfiltered.json', 'utf8'));
@@ -29,26 +28,26 @@ function filterOptimizedOnly(data) {
29
  return data
30
  }
31
 
32
- async function queryCommunityModels(req, res) {
33
  let result = data;
34
 
35
- if (req.query.sortBy) {
36
- result = sortData(result, req.query.sortBy);
37
  }
38
 
39
- if (req.query.filterBy && req.query.threshold) {
40
- result = filterData(result, req.query.filterBy, req.query.threshold ?
41
- parseFloat(req.query.threshold)
42
  :
43
  0.5
44
  );
45
  }
46
 
47
- if (req.query.optimized_only === 'true') {
48
  result = filterOptimizedOnly(result);
49
  }
50
  console.log(result.length, " items returned");
51
- res.json(makeReadable(result));
52
  }
53
 
54
  module.exports={queryCommunityModels}
 
 
1
  const fs = require('fs');
2
  // Read and Parse JSON Data
3
  const data = JSON.parse(fs.readFileSync('diffusers-unfiltered.json', 'utf8'));
 
28
  return data
29
  }
30
 
31
+ async function queryCommunityModels(queryParams) {
32
  let result = data;
33
 
34
+ if (queryParams.sortBy) {
35
+ result = sortData(result, queryParams.sortBy);
36
  }
37
 
38
+ if (queryParams.filterBy && queryParams.threshold) {
39
+ result = filterData(result, queryParams.filterBy, queryParams.threshold ?
40
+ parseFloat(queryParams.threshold)
41
  :
42
  0.5
43
  );
44
  }
45
 
46
+ if (queryParams.optimized_only === 'true') {
47
  result = filterOptimizedOnly(result);
48
  }
49
  console.log(result.length, " items returned");
50
+ return(makeReadable(result));
51
  }
52
 
53
  module.exports={queryCommunityModels}