Skip to content

Commit

Permalink
Merge pull request #18 from ful1e5/dev
Browse files Browse the repository at this point in the history
Fixes: Downloads error fixed and fetch SVG in distributing manner
  • Loading branch information
ful1e5 authored Dec 19, 2023
2 parents 9628f0f + bf7175d commit 37dace7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

### What's New?

### Fixes

- Fetch SVG by specifying `type` and `v`(version) parameters to request

## [v1.0.0-beta.0] - 19 December 2023

### What's New?
Expand Down
1 change: 0 additions & 1 deletion core/utils/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ def parse_download_params(request: Request, logger: Logger):
raise ValueError(f"Invalid version '{v}'. It should be type 'string'")
else:
version = v
raise ValueError(f"Invalid version '{v}'. It should be type 'string'")

except Exception as e:
errors.append(str(e))
Expand Down
27 changes: 17 additions & 10 deletions src/app/api/svg/fetch/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,37 @@ export async function GET(request: NextRequest) {
}

const version = request.nextUrl.searchParams.get('v');
const response = await update(version);
const type = request.nextUrl.searchParams.get('type');
const response = await update(type, version);

return NextResponse.json(
{ fetchAt: Date.now(), ...response },
{ status: 200 }
);
}

const update = async (version: string | null) => {
const update = async (type: string | null, version: string | null) => {
if (!type) {
return { error: `Invalid type: ${type}` };
}
if (!TYPES.includes(type)) {
return { error: `${type} is not available` };
}

const fetcher = new FetchSVG();

try {
const redis = new ImageRedis();

for (const type of TYPES) {
const svgs = await fetcher.fetchSVGs({ type, version });
if (!svgs) {
return { error: `Something went wrong. SVGs. not found` };
}
const key = `${type}:${version}`;
await redis.del(key);
redis.saveSVGs(key, svgs);
const svgs = await fetcher.fetchSVGs({ type, version });
if (!svgs) {
return { error: 'Something went wrong. SVGs. not found' };
}

const key = `${type}:${version}`;
await redis.del(key);
redis.saveSVGs(key, svgs);

return;
} catch (e) {
if (e instanceof Error) {
Expand Down

0 comments on commit 37dace7

Please sign in to comment.