fix: encoding
This commit is contained in:
@@ -1,47 +1,12 @@
|
||||
# aemet
|
||||
# Aemet
|
||||
Endpoint to get forecast summary to use with battery heater.
|
||||
|
||||
## 🧰 Usage
|
||||
https://697361d50005d83da5ca.functions.app.fosil.eu/
|
||||
|
||||
### GET /ping
|
||||
# Deployment
|
||||
|
||||
- Returns a "Pong" message.
|
||||
Login:
|
||||
appwrite login --endpoint "https://app.fosil.eu/v1"
|
||||
|
||||
**Response**
|
||||
|
||||
Sample `200` Response:
|
||||
|
||||
```text
|
||||
Pong
|
||||
```
|
||||
|
||||
### GET, POST, PUT, PATCH, DELETE /
|
||||
|
||||
- Returns a "Learn More" JSON response.
|
||||
|
||||
**Response**
|
||||
|
||||
Sample `200` Response:
|
||||
|
||||
```json
|
||||
{
|
||||
"motto": "Build like a team of hundreds_",
|
||||
"learn": "https://appwrite.io/docs",
|
||||
"connect": "https://appwrite.io/discord",
|
||||
"getInspired": "https://builtwith.appwrite.io"
|
||||
}
|
||||
```
|
||||
|
||||
## ⚙️ Configuration
|
||||
|
||||
| Setting | Value |
|
||||
| ----------------- | ------------- |
|
||||
| Runtime | Bun (1.0) |
|
||||
| Entrypoint | `src/main.ts` |
|
||||
| Build Commands | `bun install` |
|
||||
| Permissions | `any` |
|
||||
| Timeout (Seconds) | 15 |
|
||||
| Scopes | `users.read` |
|
||||
|
||||
## 🔒 Environment Variables
|
||||
|
||||
No environment variables required.
|
||||
Deploy:
|
||||
appwrite client --project-id="696bbb680032fc5192c9" && appwrite functions create-deployment --function-id=69736073000fadb92a9f --code="." --activate=true
|
||||
|
||||
@@ -10,9 +10,12 @@
|
||||
"typescript": "^5.4.5",
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bun": "^1.1.16",
|
||||
"@types/bun": "^1.3.6",
|
||||
"prettier": "^3.2.5",
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5",
|
||||
},
|
||||
},
|
||||
},
|
||||
"packages": {
|
||||
|
||||
@@ -13,7 +13,11 @@
|
||||
"typescript": "^5.4.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bun": "^1.1.16",
|
||||
"@types/bun": "^1.3.6",
|
||||
"prettier": "^3.2.5"
|
||||
},
|
||||
"private": true,
|
||||
"peerDependencies": {
|
||||
"typescript": "^5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,16 +16,19 @@ export default async ({ req, res, log, error }: any) => {
|
||||
throw new Error(`Error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const decoder = new TextDecoder('iso-8859-1'); // It should be iso-8859-15 but Bum v1.1 does not support it.
|
||||
const decoder = new TextDecoder('windows-1252'); // It should be iso-8859-15 but Bum v1.1 does not support it.
|
||||
let xml = decoder.decode(await response.arrayBuffer())
|
||||
|
||||
const parser = new XMLParser();
|
||||
const options = {
|
||||
attributeNamePrefix: "",
|
||||
ignoreAttributes: false
|
||||
};
|
||||
const parser = new XMLParser(options);
|
||||
let json = parser.parse(xml);
|
||||
log(json.root.prediccion)
|
||||
return res.json({ sucess: true, data: json.root.prediccion })
|
||||
|
||||
} catch(err: any) {
|
||||
let currentDay = json.root.prediccion.dia[0]
|
||||
return res.json({ sucess: true, data: currentDay })
|
||||
} catch (err: any) {
|
||||
error("Error fetching forecast: " + err.message);
|
||||
return res.json({success: false, error: err.message})
|
||||
return res.json({ success: false, error: err.message })
|
||||
}
|
||||
};
|
||||
|
||||
29
functions/aemet/tsconfig.json
Normal file
29
functions/aemet/tsconfig.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
// Environment setup & latest features
|
||||
"lib": ["ESNext"],
|
||||
"target": "ESNext",
|
||||
"module": "Preserve",
|
||||
"moduleDetection": "force",
|
||||
"jsx": "react-jsx",
|
||||
"allowJs": true,
|
||||
|
||||
// Bundler mode
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"noEmit": true,
|
||||
|
||||
// Best practices
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedIndexedAccess": true,
|
||||
"noImplicitOverride": true,
|
||||
|
||||
// Some stricter flags (disabled by default)
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"noPropertyAccessFromIndexSignature": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user