fix: send 404 when no miis are found in search API route
also remove redundant line in README
This commit is contained in:
parent
196f9d4640
commit
67bd6a4297
2 changed files with 8 additions and 17 deletions
10
API.md
10
API.md
|
|
@ -3,8 +3,6 @@
|
||||||
Welcome to the TomodachiShare API Reference!
|
Welcome to the TomodachiShare API Reference!
|
||||||
Some routes may require authentication (see [Protected](#protected-endpoints) section - _TODO_).
|
Some routes may require authentication (see [Protected](#protected-endpoints) section - _TODO_).
|
||||||
|
|
||||||
Schema properties marked with a **\*** are required.
|
|
||||||
|
|
||||||
## Public Endpoints
|
## Public Endpoints
|
||||||
|
|
||||||
### **Search Miis**
|
### **Search Miis**
|
||||||
|
|
@ -28,7 +26,7 @@ Searches Miis by name, tags, and description.
|
||||||
#### **Examples**
|
#### **Examples**
|
||||||
|
|
||||||
```
|
```
|
||||||
https://tomodachishare.com/api/search?q={query}
|
https://tomodachishare.com/api/search?q=frieren
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
@ -43,6 +41,12 @@ Returns an array of Mii IDs:
|
||||||
[1, 204, 295, 1024]
|
[1, 204, 295, 1024]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
When no Miis are found:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{ "error": "No Miis found!" }
|
||||||
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### **Get Mii Image / QR Code / Metadata Image**
|
### **Get Mii Image / QR Code / Metadata Image**
|
||||||
|
|
|
||||||
|
|
@ -29,19 +29,6 @@ export async function GET(request: NextRequest) {
|
||||||
...(gender && { gender: { equals: gender } }),
|
...(gender && { gender: { equals: gender } }),
|
||||||
};
|
};
|
||||||
|
|
||||||
const select: Prisma.MiiSelect = {
|
|
||||||
id: true,
|
|
||||||
name: true,
|
|
||||||
imageCount: true,
|
|
||||||
tags: true,
|
|
||||||
createdAt: true,
|
|
||||||
gender: true,
|
|
||||||
// Like count
|
|
||||||
_count: {
|
|
||||||
select: { likedBy: true },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const skip = (page - 1) * limit;
|
const skip = (page - 1) * limit;
|
||||||
|
|
||||||
if (sort === "random") {
|
if (sort === "random") {
|
||||||
|
|
@ -54,7 +41,7 @@ export async function GET(request: NextRequest) {
|
||||||
select: { id: true },
|
select: { id: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (matchingIds.length === 0) return;
|
if (matchingIds.length === 0) return rateLimit.sendResponse({ error: "No Miis found!" }, 404);
|
||||||
|
|
||||||
const rng = seedrandom(randomSeed.toString());
|
const rng = seedrandom(randomSeed.toString());
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue