Removed const of places api
All checks were successful
Docker Build & Publish / Build Docker (push) Successful in 1m6s

This commit is contained in:
ChrQR 2024-05-18 00:54:39 +02:00
parent 9b3a98b2ad
commit 2cac276833
2 changed files with 29 additions and 31 deletions

View File

@ -33,9 +33,8 @@ jobs:
envkey_PLACES_API: ${{ secrets.PLACES_API }} envkey_PLACES_API: ${{ secrets.PLACES_API }}
directory: . directory: .
file_name: .env.production file_name: .env.production
fail_on_empty: false fail_on_empty: true
sort_keys: false sort_keys: false
- name: Build and push 🏗️ - name: Build and push 🏗️
uses: docker/build-push-action@v5 uses: docker/build-push-action@v5
with: with:

View File

@ -1,10 +1,9 @@
'use server' "use server";
import { Forecast, LocationType, coordType } from "@/types/types"; import { Forecast, LocationType, coordType } from "@/types/types";
//takes address and returns coords in obj as {lat: number, lng: number} //takes address and returns coords in obj as {lat: number, lng: number}
export async function getLocation(searchLocation: string): Promise<coordType> { export async function getLocation(searchLocation: string): Promise<coordType> {
const placesKey = process.env.PLACES_API; const url = `https://maps.googleapis.com/maps/api/geocode/json?address=${searchLocation}&key=${process.env.PLACES_API}`;
const url = `https://maps.googleapis.com/maps/api/geocode/json?address=${searchLocation}&key=${placesKey}`;
const res = await fetch(url); const res = await fetch(url);
if (!res.ok) { if (!res.ok) {
throw new Error(`There was an error fetching the data`); throw new Error(`There was an error fetching the data`);
@ -15,16 +14,16 @@ export async function getLocation(searchLocation: string): Promise<coordType>{
} }
return { return {
name: data.results[0].formatted_address, name: data.results[0].formatted_address,
geo: data.results[0].geometry.location geo: data.results[0].geometry.location,
} };
} }
export async function getHourlyForecast(
geoLocation: coordType
export async function getHourlyForecast(geoLocation: coordType): Promise<Forecast> { ): Promise<Forecast> {
const { lat, lng } = geoLocation.geo; const { lat, lng } = geoLocation.geo;
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone; const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
const url = `https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lng}&current=temperature_2m,apparent_temperature,is_day,precipitation,rain,showers,snowfall,weather_code,cloud_cover,wind_speed_10m,wind_direction_10m&hourly=temperature_2m,apparent_temperature,precipitation_probability,precipitation,weather_code,wind_speed_10m,is_day&daily=weather_code,temperature_2m_max,temperature_2m_min,apparent_temperature_max,apparent_temperature_min,sunrise,sunset,daylight_duration,sunshine_duration,uv_index_max,precipitation_sum,precipitation_hours,wind_speed_10m_max&timezone=${tz}` const url = `https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lng}&current=temperature_2m,apparent_temperature,is_day,precipitation,rain,showers,snowfall,weather_code,cloud_cover,wind_speed_10m,wind_direction_10m&hourly=temperature_2m,apparent_temperature,precipitation_probability,precipitation,weather_code,wind_speed_10m,is_day&daily=weather_code,temperature_2m_max,temperature_2m_min,apparent_temperature_max,apparent_temperature_min,sunrise,sunset,daylight_duration,sunshine_duration,uv_index_max,precipitation_sum,precipitation_hours,wind_speed_10m_max&timezone=${tz}`;
const res = await fetch(url); const res = await fetch(url);
if (!res.ok) { if (!res.ok) {
throw new Error(`Failed to fetch the weather data`); throw new Error(`Failed to fetch the weather data`);