Add rewrite
This commit is contained in:
@@ -32,6 +32,7 @@ export default defineOAuthStravaEventHandler({
|
||||
sex: auth.user.sex,
|
||||
weight: auth.user.weight,
|
||||
avatar: auth.user.profile,
|
||||
premium: false,
|
||||
};
|
||||
|
||||
const db = useDrizzle();
|
||||
@@ -41,7 +42,7 @@ export default defineOAuthStravaEventHandler({
|
||||
.values(userPayload)
|
||||
.onConflictDoUpdate({
|
||||
target: tables.users.id,
|
||||
set: omit(userPayload, ["id"]),
|
||||
set: omit(userPayload, ["id", "premium"]),
|
||||
})
|
||||
.returning();
|
||||
|
||||
@@ -77,7 +78,7 @@ export default defineOAuthStravaEventHandler({
|
||||
.onConflictDoNothing();
|
||||
|
||||
await setUserSession(event, {
|
||||
user: userPayload,
|
||||
user: { ...userPayload, premium: user.premium },
|
||||
});
|
||||
|
||||
sendRedirect(event, "/");
|
||||
|
||||
@@ -20,7 +20,10 @@ export default defineEventHandler(async (event) => {
|
||||
|
||||
const activity = await strava!<any>(`/activities/${body.object_id}`);
|
||||
|
||||
const [aiError, aiResponse] = await createActivityContent(activity, user);
|
||||
const [aiError, stravaRequestBody] = await createActivityContent(
|
||||
activity,
|
||||
user,
|
||||
);
|
||||
if (aiError) {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
@@ -28,20 +31,6 @@ export default defineEventHandler(async (event) => {
|
||||
});
|
||||
}
|
||||
|
||||
const responseObject = JSON.parse(
|
||||
get(aiResponse, "output.0.content.0.text"),
|
||||
) as {
|
||||
title: string;
|
||||
description: string;
|
||||
};
|
||||
|
||||
const promo = "Written by https://ghostwriter.rocks 👻";
|
||||
|
||||
const stravaRequestBody = {
|
||||
name: responseObject.title,
|
||||
description: [responseObject.description, promo].join("\n"),
|
||||
};
|
||||
|
||||
await strava!(`activities/${body.object_id}`, {
|
||||
method: "PUT",
|
||||
body: stravaRequestBody,
|
||||
|
||||
Reference in New Issue
Block a user