Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions deepwell/src/services/domain/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ impl DomainService {
format!("{}{}", site_slug, config.main_domain)
}

#[inline]
pub fn get_files(config: &Config, site_slug: &str) -> String {
// 'files_domain' is already prefixed with .
format!("{}{}", site_slug, config.files_domain)
}

/// Gets the preferred domain for the given site.
pub fn preferred_domain<'a>(config: &'a Config, site: &'a SiteModel) -> Cow<'a, str> {
debug!(
Expand Down
25 changes: 20 additions & 5 deletions deepwell/src/services/view/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ use crate::models::site::Model as SiteModel;
use crate::services::render::RenderOutput;
use crate::services::special_page::{GetSpecialPageOutput, SpecialPageType};
use crate::services::{
PageRevisionService, PageService, SessionService, SiteService, SpecialPageService,
TextService, UserService,
DomainService, PageRevisionService, PageService, SessionService, SiteService,
SpecialPageService, TextService, UserService,
};
use crate::utils::{parse_locales, split_category};
use ftml::prelude::*;
Expand Down Expand Up @@ -68,7 +68,11 @@ impl ViewService {

let mut locales = parse_locales(&locales_str)?;
let config = ctx.config();
let Viewer { site, user_session } = Self::get_viewer(
let Viewer {
site,
site_file_domain,
user_session,
} = Self::get_viewer(
ctx,
&mut locales,
site_id,
Expand Down Expand Up @@ -244,7 +248,11 @@ impl ViewService {

// TODO Check if user-agent and IP match?

let viewer = Viewer { site, user_session };
let viewer = Viewer {
site,
site_file_domain,
user_session,
};
let output = match status {
PageStatus::Found {
page,
Expand Down Expand Up @@ -436,6 +444,8 @@ impl ViewService {
) -> Result<Viewer> {
info!("Getting viewer data site ID {site_id} and session token");

let config = ctx.config();

// Get user data from session token (if present)
let user_session = match session_token {
Some("") | None => None,
Expand Down Expand Up @@ -481,9 +491,14 @@ impl ViewService {

// Get site information
let site = SiteService::get(ctx, Reference::Id(site_id)).await?;
let site_file_domain = DomainService::get_files(config, &site.slug);

// Return
Ok(Viewer { site, user_session })
Ok(Viewer {
site,
site_file_domain,
user_session,
})
}

async fn can_access_page(
Expand Down
1 change: 1 addition & 0 deletions deepwell/src/services/view/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ pub enum GetAdminViewOutput {
#[derive(Serialize, Debug, Clone)]
pub struct Viewer {
pub site: SiteModel,
pub site_file_domain: String,
pub user_session: Option<UserSession>,
}

Expand Down
2 changes: 2 additions & 0 deletions framerail/src/lib/server/deepwell/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export async function siteUpdate(
slug: Optional<String>,
tagline: Optional<String>,
description: Optional<String>,
defaultPage: Optional<String>,
locale: Optional<String>,
layout: Optional<Nullable<Layout>>
): Promise<object> {
Expand All @@ -19,6 +20,7 @@ export async function siteUpdate(
slug,
tagline,
description,
default_page: defaultPage,
locale,
layout:
layout !== undefined
Expand Down
1 change: 1 addition & 0 deletions framerail/src/lib/server/load/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export async function loadAdminPage(request, cookies) {
"site-info.slug": {},
"site-info.tagline": {},
"site-info.description": {},
"site-info.default-page": {},
"site-info.locale": {},
"site-info.layout": {},
"wiki-page-layout.default": {},
Expand Down
24 changes: 19 additions & 5 deletions framerail/src/routes/[slug]/[...extra]/FilePane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,7 @@
class="action-button deleted-file clickable"
type="button"
on:click={() => {
showFiles = false
getFileList(true).then(() => {
showFiles = true
})
getFileList(true)
}}
>
{$page.data.internationalization?.restore}
Expand Down Expand Up @@ -266,7 +263,10 @@
{#each [...fileMap].sort((a, b) => b[0] - a[0]) as [_, file] (file.file_id)}
<div class="file-row" data-id={file.file_id}>
<div class="file-attribute name">
{file.name}
<a
href="//{$page.data.site_file_domain}/-/file/{$page.data.page
.slug}/{file.name}">{file.name}</a
>
</div>
<div class="file-attribute created-at">
{new Date(file.file_created_at).toLocaleString()}
Expand Down Expand Up @@ -656,4 +656,18 @@
}
}
}

.revision-list {
display: table;
width: 100%;

.revision-header,
.revision-row {
display: table-row;

.revision-attribute {
display: table-cell;
}
}
}
</style>
3 changes: 0 additions & 3 deletions framerail/src/routes/[slug]/[...extra]/VotePane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
let fdata = new FormData()
fdata.set("site-id", $page.data.site.site_id)
fdata.set("page-id", $page.data.page.page_id)
fdata.set("action", "get_list")
let res = await fetch(`/${$page.data.page.slug}/vote-get`, {
method: "POST",
body: fdata
Expand All @@ -34,7 +33,6 @@
let fdata = new FormData()
fdata.set("site-id", $page.data.site.site_id)
fdata.set("page-id", $page.data.page.page_id)
fdata.set("action", "set")
fdata.set("value", value ?? 0)
let res = await fetch(`/${$page.data.page.slug}/vote-cast`, {
method: "POST",
Expand All @@ -53,7 +51,6 @@
let fdata = new FormData()
fdata.set("site-id", $page.data.site.site_id)
fdata.set("page-id", $page.data.page.page_id)
fdata.set("action", "remove")
let res = await fetch(`/${$page.data.page.slug}/vote-cancel`, {
method: "POST",
body: fdata
Expand Down
18 changes: 18 additions & 0 deletions framerail/src/routes/[x+2d]/admin/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@
type="text"
value={$page.data.site.description}
/>
<label for="default-page"
>{$page.data.internationalization?.["site-info.default-page"]}</label
>
<input
name="default-page"
class="site-attribute default-page"
type="text"
value={$page.data.site.default_page}
/>
<label for="locale">{$page.data.internationalization?.["site-info.locale"]}</label>
<input
name="locale"
Expand Down Expand Up @@ -144,6 +153,15 @@
</div>
{/if}

{#if $page.data.site.default_page}
<div class="site-attribute default-page">
<span class="site-attribute-label"
>{$page.data.internationalization?.["site-info.default-page"]}</span
>
<span class="site-attribute-value">{$page.data.site.default_page}</span>
</div>
{/if}

{#if $page.data.site.locale}
<div class="site-attribute locale">
<span class="site-attribute-label"
Expand Down
2 changes: 2 additions & 0 deletions framerail/src/routes/[x+2d]/admin/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export async function POST(event) {
let slug = data.get("slug")?.toString()
let tagline = data.get("tagline")?.toString()
let description = data.get("description")?.toString()
let defaultPage = data.get("default-page")?.toString()
let locale = data.get("locale")?.toString()
let layout = data.get("layout")?.toString().trim()

Expand All @@ -36,6 +37,7 @@ export async function POST(event) {
slug,
tagline,
description,
defaultPage,
locale,
layout
)
Expand Down
1 change: 1 addition & 0 deletions locales/fluent/admin-panel/en.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ site-info =
.slug = Site domain:
.tagline = Site tagline/subtitle:
.description = Site description:
.default-page = Site default page:
.locale = Site locale:
.layout = Site layout:

Expand Down
1 change: 1 addition & 0 deletions locales/fluent/admin-panel/zh_Hans.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ site-info =
.slug = 网站域名:
.tagline = 网站副标题:
.description = 网站描述:
.default-page = 网站主页面:
.locale = 网站语言:
.layout = 网站布局:

Expand Down
1 change: 1 addition & 0 deletions web/scripts/vite-pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ json.main = `./cjs/wj-${package}.cjs`
json.module = `./esm/wj-${package}.mjs`
json.exports ??= {}
json.exports["."] = {
types: json.types,
import: `./esm/wj-${package}.mjs`,
require: `./cjs/wj-${package}.cjs`
}
Expand Down
Loading