generated from xmartlabs/flutter-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Edge function improvement (#21)
- Loading branch information
Showing
11 changed files
with
127 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"deno.enable": true, | ||
"deno.lint": true, | ||
"deno.unstable": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
// https://deno.land/manual/getting_started/setup_your_environment | ||
// This enables autocomplete, go to definition, etc. | ||
|
||
import { serve } from "https://deno.land/[email protected]/http/server.ts" | ||
import { serve } from "https://deno.land/[email protected]/http/server.ts"; | ||
import { createClient } from "https://esm.sh/@supabase/[email protected]?target=deno"; | ||
|
||
const supabaseClient = createClient( | ||
|
@@ -12,33 +12,45 @@ const supabaseClient = createClient( | |
global: { | ||
headers: { | ||
Authorization: "Bearer " + Deno.env.get("SUPABASE_SERVICE_ROLE_KEY"), | ||
"Access-Control-Allow-Origin": "*", | ||
}, | ||
}, | ||
}, | ||
); | ||
|
||
serve(async (req) => { | ||
const { id } = await req.json() | ||
export const corsHeaders = { | ||
"Access-Control-Allow-Origin": "*", | ||
"Access-Control-Allow-Headers": | ||
"authorization, x-client-info, apikey, content-type", | ||
}; | ||
|
||
const { data, error: getBodyError } = await supabaseClient.from("messages").select("body").eq("id", id) | ||
const createApiResponse = (statusCode: number, body: { message: string }) => { | ||
const headers = { ...corsHeaders, "Content-Type": "application/json" }; | ||
return new Response(JSON.stringify(body), { headers, status: statusCode }); | ||
}; | ||
|
||
if (getBodyError != null) { | ||
return new Response(JSON.stringify({ "message": "Error getting message body" }), { headers: { "Content-Type": "application/json" } },) | ||
serve(async (req) => { | ||
// Required for web browsers | ||
if (req.method === "OPTIONS") { | ||
return createApiResponse(200, { message: "ok" }); | ||
} | ||
|
||
const body = data[0].body | ||
const { id } = await req.json(); | ||
const { data: messages, error: getBodyError } = await supabaseClient.from( | ||
"messages", | ||
).select("body").eq("id", id); | ||
|
||
const capitalizedMessage = body.toUpperCase() | ||
if (getBodyError != null || !messages || messages.length !== 1) { | ||
return createApiResponse(400, { message: "Error getting message" }); | ||
} | ||
|
||
const { error: updateMessageError } = await supabaseClient.from("messages").update({ body: capitalizedMessage }).eq("id", id) | ||
const capitalizedBody = messages[0].body.toUpperCase(); | ||
const { error: updateMessageError } = await supabaseClient.from("messages") | ||
.update({ body: capitalizedBody }).eq("id", id); | ||
|
||
if (updateMessageError != null) { | ||
return new Response(JSON.stringify({ "message": "Error updating message" }), { headers: { "Content-Type": "application/json" } },) | ||
return createApiResponse(500, { message: "Error updating message" }); | ||
} | ||
|
||
|
||
return new Response( | ||
JSON.stringify({ "message": "Success" }), | ||
{ headers: { "Content-Type": "application/json" } }, | ||
) | ||
}) | ||
return createApiResponse(200, { "message": "Success" }); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import 'dart:math'; | ||
|
||
import 'package:flutter_screenutil/flutter_screenutil.dart'; | ||
|
||
extension SizeExtension on num { | ||
double get wf => min(this * 1.08, w); | ||
|
||
double get hf => min(this * 1.08, h); | ||
|
||
double get rf => min(this * 1.08, r); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters