Skip to content

Commit

Permalink
Merge pull request #303 from appwrite/chores-remove-send-method
Browse files Browse the repository at this point in the history
Chores: Remove send method
  • Loading branch information
christyjacob4 authored Aug 16, 2024
2 parents 619d2c9 + 1d3f022 commit cbb7089
Show file tree
Hide file tree
Showing 77 changed files with 205 additions and 205 deletions.
4 changes: 2 additions & 2 deletions bun/sync-with-meilisearch/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default async ({ req, res, log }) => {
MEILISEARCH_SEARCH_API_KEY: Bun.env.MEILISEARCH_SEARCH_API_KEY,
});

return res.send(html, 200, { "Content-Type": "text/html; charset=utf-8" });
return res.text(html, 200, { "Content-Type": "text/html; charset=utf-8" });
}

const client = new Client()
Expand Down Expand Up @@ -66,5 +66,5 @@ export default async ({ req, res, log }) => {

log("Sync finished.");

return res.send("Sync finished.", 200);
return res.text("Sync finished.", 200);
};
6 changes: 3 additions & 3 deletions bun/sync-with-qdrant/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default async ({ req, res, log }: Context) => {

if (req.method === 'GET') {
const html = getStaticFile('index.html');
return res.send(html, 200, { 'Content-Type': 'text/html; charset=utf-8' });
return res.text(html, 200, { 'Content-Type': 'text/html; charset=utf-8' });
}

if (req.method !== 'POST') {
Expand All @@ -33,7 +33,7 @@ export default async ({ req, res, log }: Context) => {
if (req.path === '/search') {
const queryEmbedding = await openai.embeddings.create({
model: 'text-embedding-3-small',
input: req.body.prompt,
input: req.bodyJson.prompt,
});

const searchResults = await client.search(
Expand Down Expand Up @@ -79,7 +79,7 @@ export default async ({ req, res, log }: Context) => {
await client.upsert(process.env.QDRANT_COLLECTION_NAME, {
points,
});
return res.send('Sync finished.', 200);
return res.text('Sync finished.', 200);
};

type Context = {
Expand Down
10 changes: 5 additions & 5 deletions bun/whatsapp-with-vonage/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default async ({ req, res, log, error }: Context) => {
]);

if (req.method === "GET") {
return res.send(getStaticFile("index.html"), 200, {
return res.text(getStaticFile("index.html"), 200, {
"Content-Type": "text/html; charset=utf-8",
});
}
Expand All @@ -35,14 +35,14 @@ export default async ({ req, res, log, error }: Context) => {
}

const hasher = new Bun.CryptoHasher("sha256");
const hashedValue = hasher.update(req.bodyRaw).digest("hex").toString();
const hashedValue = hasher.update(req.bodyBinary).digest("hex").toString();

if (hashedValue != decodedToken["payload_hash"]) {
return res.json({ ok: false, error: "Payload hash mismatched" }, 401);
}

try {
throwIfMissing(req.body, ["from", "text"]);
throwIfMissing(req.bodyJson, ["from", "text"]);
} catch (err) {
return res.json({ ok: false, error: err.message }, 400);
}
Expand All @@ -55,9 +55,9 @@ export default async ({ req, res, log, error }: Context) => {
method: "POST",
body: JSON.stringify({
from: Bun.env.VONAGE_WHATSAPP_NUMBER,
to: req.body.from,
to: req.bodyJson.from,
message_type: "text",
text: `You sent me: ${req.body.text}`,
text: `You sent me: ${req.bodyJson.text}`,
channel: "whatsapp",
}),
headers: {
Expand Down
6 changes: 3 additions & 3 deletions dart/censor_with_redact/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ Future<dynamic> main(final context) async {
throwIfMissing(Platform.environment, ['PANGEA_REDACT_TOKEN']);

if (context.req.method == 'GET') {
return context.res.send(getStaticFile('index.html'), 200,
return context.res.text(getStaticFile('index.html'), 200,
{'Content-Type': 'text/html; charset=utf-8'});
}

try {
throwIfMissing(context.req.body, ['text']);
throwIfMissing(context.req.bodyJson, ['text']);
} catch (err) {
return context.res.json({'ok': false, 'error': err.toString()});
}
Expand All @@ -26,7 +26,7 @@ Future<dynamic> main(final context) async {
'Bearer ${Platform.environment['PANGEA_REDACT_TOKEN']}',
},
body: jsonEncode({
'text': context.req.body['text'],
'text': context.req.bodyJson['text'],
}));

final data = jsonDecode(response.body);
Expand Down
6 changes: 3 additions & 3 deletions dart/prompt_chatgpt/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ Future<dynamic> main(final context) async {
throwIfMissing(Platform.environment, ['OPENAI_API_KEY']);

if (context.req.method == 'GET') {
return context.res.send(getStaticFile('index.html'), 200,
return context.res.text(getStaticFile('index.html'), 200,
{'Content-Type': 'text/html; charset=utf-8'});
}

try {
throwIfMissing(context.req.body, ['prompt']);
throwIfMissing(context.req.bodyJson, ['prompt']);
} catch (err) {
return context.res.json({'ok': false, 'error': err.toString()});
}
Expand All @@ -25,7 +25,7 @@ Future<dynamic> main(final context) async {
maxTokens: int.parse(Platform.environment['OPENAI_MAX_TOKENS'] ?? '512'),
messages: [
OpenAIChatCompletionChoiceMessageModel(
content: context.req.body['prompt'],
content: context.req.bodyJson['prompt'],
role: OpenAIChatMessageRole.user)
],
);
Expand Down
10 changes: 5 additions & 5 deletions dart/whatsapp_with_vonage/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Future<dynamic> main(final context) async {
]);

if (context.req.method == 'GET') {
return context.res.send(getStaticFile('index.html'), 200,
return context.res.text(getStaticFile('index.html'), 200,
{'Content-Type': 'text/html; charset=utf-8'});
}

Expand All @@ -24,7 +24,7 @@ Future<dynamic> main(final context) async {
return context.res.json({'ok': false, 'error': 'Unauthorized'}, 401);
}

if (context.req.body['from'] == null || context.req.body['text'] == null) {
if (context.req.bodyJson['from'] == null || context.req.bodyJson['text'] == null) {
return context.res.json({'ok': false, 'error': 'Missing required fields.'}, 400);
}

Expand All @@ -34,7 +34,7 @@ Future<dynamic> main(final context) async {
return context.res.json({'ok': false, 'error': 'Missing payload hash.'}, 400);
}

final payloadHash = sha256.convert(utf8.encode(context.req.bodyRaw)).toString();
final payloadHash = sha256.convert(utf8.encode(context.req.bodyBinary)).toString();

if (jwt.payload['payload_hash'] != payloadHash) {
return context.res.json({'ok': false, 'error': 'Payload hash mismatch.'}, 401);
Expand All @@ -50,9 +50,9 @@ Future<dynamic> main(final context) async {
},
body: jsonEncode({
'from': Platform.environment['VONAGE_WHATSAPP_NUMBER'],
'to': context.req.body['from'],
'to': context.req.bodyJson['from'],
'message_type': 'text',
'text': 'Hi there! You sent me: ${context.req.body['text']}',
'text': 'Hi there! You sent me: ${context.req.bodyJson['text']}',
'channel': 'whatsapp',
}),
);
Expand Down
4 changes: 2 additions & 2 deletions deno/sync-with-meilisearch/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default async ({ req, res, log, error }: any) => {
MEILISEARCH_SEARCH_API_KEY: Deno.env.get("MEILISEARCH_SEARCH_API_KEY"),
});

return new res.send(html, 200, {
return new res.text(html, 200, {
"Content-Type": "text/html; charset=utf-8",
});
}
Expand Down Expand Up @@ -74,5 +74,5 @@ export default async ({ req, res, log, error }: any) => {

log("Sync finished.");

return res.send("Sync finished.", 200);
return res.text("Sync finished.", 200);
};
10 changes: 5 additions & 5 deletions deno/whatsapp-with-vonage/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default async ({ req, res, log, error }: Context) => {
]);

if (req.method === "GET") {
return res.send(getStaticFile("index.html"), 200, {
return res.text(getStaticFile("index.html"), 200, {
"Content-Type": "text/html; charset=utf-8",
});
}
Expand All @@ -40,15 +40,15 @@ export default async ({ req, res, log, error }: Context) => {

const hash = crypto.subtle.digestSync(
"SHA-256",
new TextEncoder().encode(req.bodyRaw),
new TextEncoder().encode(req.bodyBinary),
);

if (encodeHex(hash) !== payload.payload_hash) {
return res.json({ ok: false, error: "Payload hash mismatch." }, 401);
}

try {
throwIfMissing(req.body, ["from", "text"]);
throwIfMissing(req.bodyJson, ["from", "text"]);
} catch (err) {
return res.json({ ok: false, error: err.message }, 400);
}
Expand All @@ -61,9 +61,9 @@ export default async ({ req, res, log, error }: Context) => {
method: "POST",
body: JSON.stringify({
from: Deno.env.get("VONAGE_WHATSAPP_NUMBER"),
to: req.body.from,
to: req.bodyJson.from,
message_type: "text",
text: `Hi there! You sent me: ${req.body.text}`,
text: `Hi there! You sent me: ${req.bodyJson.text}`,
channel: "whatsapp",
}),
headers: {
Expand Down
2 changes: 1 addition & 1 deletion kotlin/starter/src/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Main {
if (context.req.path == "/ping") {
// Use res object to respond with text(), json(), or binary()
// Don't forget to return a response!
return context.res.send("Pong")
return context.res.text("Pong")
}

return context.res.json(mutableMapOf(
Expand Down
4 changes: 2 additions & 2 deletions kotlin/sync-with-meilisearch/src/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Main {
"MEILISEARCH_SEARCH_API_KEY" to System.getenv("MEILISEARCH_SEARCH_API_KEY"),
))

return context.res.send(html, 200, mapOf("content-type" to "text/html"))
return context.res.text(html, 200, mapOf("content-type" to "text/html"))
}

val client = AppwriteClient().apply {
Expand Down Expand Up @@ -78,6 +78,6 @@ class Main {

context.log("Sync finished.");

return context.res.send("Sync finished.");
return context.res.text("Sync finished.");
}
}
6 changes: 3 additions & 3 deletions node-typescript/github-issue-bot/src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ class GithubService {

return (
typeof signature !== 'string' ||
(await verify(process.env.GITHUB_WEBHOOK_SECRET, req.bodyRaw, signature))
(await verify(process.env.GITHUB_WEBHOOK_SECRET, req.bodyBinary, signature))
);
}

isIssueOpenedEvent(req: any): boolean {
return (
req.headers['x-github-event'] === 'issues' &&
req.body.issue &&
req.body.action === 'opened'
req.bodyJson.issue &&
req.bodyJson.action === 'opened'
);
}

Expand Down
6 changes: 3 additions & 3 deletions node-typescript/github-issue-bot/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export default async ({ res, req, log, error }: Context) => {
}

await github.postComment(
req.body.repository,
req.body.issue,
`Thanks for the issue report @${req.body.issue.user.login}! We will look into it as soon as possible.`
req.bodyJson.repository,
req.bodyJson.issue,
`Thanks for the issue report @${req.bodyJson.issue.user.login}! We will look into it as soon as possible.`
);

return res.json({ ok: true });
Expand Down
4 changes: 2 additions & 2 deletions node-typescript/sync-with-meilisearch/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default async ({ req, res, log }: Context) => {
MEILISEARCH_SEARCH_API_KEY: process.env.MEILISEARCH_SEARCH_API_KEY,
});

return res.send(html, 200, { 'Content-Type': 'text/html; charset=utf-8' });
return res.text(html, 200, { 'Content-Type': 'text/html; charset=utf-8' });
}

const client = new Client()
Expand Down Expand Up @@ -75,5 +75,5 @@ export default async ({ req, res, log }: Context) => {

log('Sync finished.');

return res.send('Sync finished.', 200);
return res.text('Sync finished.', 200);
};
6 changes: 3 additions & 3 deletions node-typescript/sync-with-qdrant/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default async ({ req, res, log }: Context) => {

if (req.method === 'GET') {
const html = getStaticFile('index.html');
return res.send(html, 200, { 'Content-Type': 'text/html; charset=utf-8' });
return res.text(html, 200, { 'Content-Type': 'text/html; charset=utf-8' });
}

if (req.method !== 'POST') {
Expand All @@ -33,7 +33,7 @@ export default async ({ req, res, log }: Context) => {
if (req.path === '/search') {
const queryEmbedding = await openai.embeddings.create({
model: 'text-embedding-3-small',
input: req.body.prompt,
input: req.bodyJson.prompt,
});

const searchResults = await client.search(
Expand Down Expand Up @@ -79,7 +79,7 @@ export default async ({ req, res, log }: Context) => {
await client.upsert(process.env.QDRANT_COLLECTION_NAME, {
points,
});
return res.send('Sync finished.', 200);
return res.text('Sync finished.', 200);
};

type Context = {
Expand Down
8 changes: 4 additions & 4 deletions node-typescript/whatsapp-with-vonage/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default async ({ req, res, log, error }: Context) => {
]);

if (req.method === 'GET') {
return res.send(getStaticFile('index.html'), 200, {
return res.text(getStaticFile('index.html'), 200, {
'Content-Type': 'text/html; charset=utf-8',
});
}
Expand All @@ -41,7 +41,7 @@ export default async ({ req, res, log, error }: Context) => {
return res.json({ ok: false, error: err.message }, 400);
}

if (sha256(req.bodyRaw) !== (decoded as JwtPayload).payload_hash) {
if (sha256(req.bodyBinary) !== (decoded as JwtPayload).payload_hash) {
return res.json({ ok: false, error: 'Payload hash mismatch.' }, 401);
}

Expand All @@ -60,9 +60,9 @@ export default async ({ req, res, log, error }: Context) => {
method: 'POST',
body: JSON.stringify({
from: process.env.VONAGE_WHATSAPP_NUMBER,
to: req.body.from,
to: req.bodyJson.from,
message_type: 'text',
text: `Hi there! You sent me: ${req.body.text}`,
text: `Hi there! You sent me: ${req.bodyJson.text}`,
channel: 'whatsapp',
}),
headers: {
Expand Down
6 changes: 3 additions & 3 deletions node/analyze-with-perspectiveapi/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ export default async ({ req, res }) => {
throwIfMissing(process.env, ['PERSPECTIVE_API_KEY']);

if (req.method === 'GET') {
return res.send(getStaticFile('index.html'), 200, {
return res.text(getStaticFile('index.html'), 200, {
'Content-Type': 'text/html; charset=utf-8',
});
}

if (!req.body.text || typeof req.body.text !== 'string') {
if (!req.bodyJson.text || typeof req.bodyJson.text !== 'string') {
return res.json({ ok: false, error: 'Missing required field `text`' }, 400);
}

Expand All @@ -23,7 +23,7 @@ export default async ({ req, res }) => {
},
body: JSON.stringify({
comment: {
text: req.body.text,
text: req.bodyJson.text,
type: 'PLAIN_TEXT',
},
languages: ['en'],
Expand Down
Loading

0 comments on commit cbb7089

Please sign in to comment.