Skip to content

Commit

Permalink
Pro feature: Ability to use text-only layout for main page
Browse files Browse the repository at this point in the history
  • Loading branch information
siddug committed Apr 29, 2024
1 parent a9f594d commit f7a515d
Show file tree
Hide file tree
Showing 11 changed files with 248 additions and 108 deletions.
1 change: 1 addition & 0 deletions btw.sql
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,6 @@ CREATE TABLE "btw"."users" (
"pro" bool,
"umami_site_id" uuid,
"share_id" text,
"settings" json,
PRIMARY KEY ("processed_email")
);
1 change: 1 addition & 0 deletions publisher/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const getCommonDeets = (
instagram: user.instagram,
umami_site_id: user.umami_site_id,
umami_src: process.env.UMAMI_SOURCE,
settings: user.settings,
};
};

Expand Down
4 changes: 2 additions & 2 deletions publisher/views/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
<div class="space-y-8">
{{#each notes}}
<a class="post-item flex" href="{{url}}">
<div style="margin-top: 5px;" class="hidden sm:block w-32 h-32 flex-shrink-0">{{#if image}}<img class="w-full h-full object-center object-cover" src="{{image}}"/>{{else}}<div class="w-full h-full bg-gray-200"></div>{{/if}}</div>
{{#not ../../settings.removeImagesInMainPage}}<div style="margin-top: 5px;" class="hidden sm:block w-32 h-32 flex-shrink-0">{{#if image}}<img class="w-full h-full object-center object-cover" src="{{image}}"/>{{else}}<div class="w-full h-full bg-gray-200"></div>{{/if}}</div>{{/not}}
<div class="ml-6 flex flex-col">
<h3 class="text-xl font-bold ">{{title}}</h3>
<div class="text-xs text-gray-500 mt-1 mb-4"><span>{{readableDate}}</span></div>
<div class="text-xs text-gray-500 mt-1 {{#not ../../settings.removeImagesInMainPage}}mb-4{{else}}mb-2{{/not}}"><span>{{readableDate}}</span></div>
<div class="flex-grow">{{{excerpt}}}</div>
</div>
</a>
Expand Down
18 changes: 15 additions & 3 deletions tasks/logic/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ async function setUserDetails({
instagram,
linkedin,
user_id,
settings,
}) {
const tasksDB = await db.getTasksDB();

Expand All @@ -540,7 +541,8 @@ async function setUserDetails({
pic,
twitter,
instagram,
linkedin
linkedin,
settings
);

if (!slug) {
Expand Down Expand Up @@ -577,8 +579,18 @@ async function setUserDetails({

try {
await tasksDB.query(
`UPDATE btw.users SET name = $1, slug = $2, bio = $3, pic = $4, twitter = $5, linkedin = $6, instagram = $7 WHERE id = $8`,
[name, slug, bio, pic, twitter, linkedin, instagram, user_id]
`UPDATE btw.users SET name = $1, slug = $2, bio = $3, pic = $4, twitter = $5, linkedin = $6, instagram = $7, settings = $8 WHERE id = $9`,
[
name,
slug,
bio,
pic,
twitter,
linkedin,
instagram,
settings,
user_id,
]
);

userCacheHelper(user_id);
Expand Down
21 changes: 20 additions & 1 deletion tasks/routes/otp.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,26 @@ router.post(
origin: process.env.CORS_DOMAINS.split(","),
}),
async (req, res) => {
const { email } = req.body;
let { email } = req.body;

if (
!Number(process.env.TURN_OFF_SINGLE_USER_MODE) &&
process.env.ADMIN_EMAIL
) {
// Single user mode is on
email = process.env.ADMIN_EMAIL;
}

if (
!Number(process.env.TURN_OFF_SINGLE_USER_MODE) &&
process.env.ADMIN_OTP
) {
// admin otp is set. no need to email it.
res.json({
success: true,
});
return;
}

// check that otp is in right format
if (!email || !email.match(/^[^\s@]+@[^\s@]+\.[^\s@]+$/)) {
Expand Down
10 changes: 5 additions & 5 deletions tasks/routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,9 @@ router.post(
: {}),
});
} else if (
!Number(
process.env.TURN_OFF_SINGLE_USER_MODE &&
!process.env.ADMIN_OTP &&
loginToken
)
!Number(process.env.TURN_OFF_SINGLE_USER_MODE) &&
!process.env.ADMIN_OTP &&
loginToken
) {
// single user mode. otp is not set. loginToken exists.
// check that this logintoken exists. if it doesn't exist, then delete the cookie so that user state will be forced to be reset
Expand Down Expand Up @@ -182,6 +180,7 @@ router.post(
twitter,
linkedin,
instagram,
settings,
} = req.body || {};

// get loginToken as btw_uuid cookie
Expand All @@ -203,6 +202,7 @@ router.post(
twitter,
linkedin,
instagram,
settings,
})
);
} catch (e) {
Expand Down
Loading

0 comments on commit f7a515d

Please sign in to comment.