work on porting over contact form from old site, also added initial db support

to use later
This commit is contained in:
badblocks 2026-01-06 08:07:19 -08:00
parent 8d989ef36f
commit f641dac69b
No known key found for this signature in database
12 changed files with 232 additions and 32 deletions

View file

@ -0,0 +1,46 @@
const httpFetchClient = {
get: async (url: string, headers: Record<string, string>) => {
const response = await fetch(url, {
method: "GET",
headers,
});
return response.json();
},
post: async (url: string, body: JSON, headers: Record<string, string>) => {
const response = await fetch(url, {
method: "POST",
headers,
body: JSON.stringify(body),
});
return response.json();
},
put: async (url: string, body: JSON, headers: Record<string, string>) => {
const response = await fetch(url, {
method: "PUT",
headers,
body: JSON.stringify(body),
});
return response.json();
},
patch: async (url: string, body: JSON, headers: Record<string, string>) => {
const response = await fetch(url, {
method: "PATCH",
headers,
body: JSON.stringify(body),
});
return response.json();
},
delete: async (url: string, headers: Record<string, string>) => {
const response = await fetch(url, {
method: "DELETE",
headers,
});
return response.json();
},
};
export default httpFetchClient;

View file

@ -0,0 +1,53 @@
import Client from "android-sms-gateway";
import {
ANDROID_SMS_GATEWAY_LOGIN,
ANDROID_SMS_GATEWAY_PASSWORD,
ANDROID_SMS_GATEWAY_RECIPIENT_PHONE,
ANDROID_SMS_GATEWAY_URL,
} from "astro:env/server";
import httpFetchClient from "@lib/HttpFetchClient";
class SmsClient {
readonly api: Client;
constructor() {
this.api = new Client(
ANDROID_SMS_GATEWAY_LOGIN,
ANDROID_SMS_GATEWAY_PASSWORD,
httpFetchClient,
ANDROID_SMS_GATEWAY_URL,
);
}
async sendSMS(message: string) {
const bundle = {
phoneNumbers: [ANDROID_SMS_GATEWAY_RECIPIENT_PHONE], // hard-coded on purpose ;)
message: message,
};
try {
const msg_state = await this.api.send(bundle);
return {
success: true,
id: msg_state.id,
state: msg_state.state,
};
} catch (error) {
return { success: false, error: error };
}
}
async update(id: string) {
try {
const msg_state = await this.api.getState(id);
return {
success: true,
id: msg_state.id,
state: msg_state.state,
};
} catch (error) {
return { success: false, id: id, error: error };
}
}
}
export default SmsClient;