Skip to content

Commit cded4e1

Browse files
committed
add enterprise
1 parent 73efa9c commit cded4e1

5 files changed

Lines changed: 98 additions & 10 deletions

File tree

src/hugoverse.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class Hugoverse {
7777
* -F "type=MDFPreview" \
7878
* -F "host_name=MDFriday Share"
7979
*/
80-
async deployMDFridayPreview(id: string): Promise<string> {
80+
async deployMDFridayPreview(id: string, licenseKey: string = ''): Promise<string> {
8181
try {
8282
const createPostUrl = `${this.apiUrl}/api/mdf/preview/deploy?type=MDFPreview&id=${id}`;
8383

@@ -86,6 +86,7 @@ export class Hugoverse {
8686
body.append("type", "MDFPreview");
8787
body.append("id", id);
8888
body.append("host_name", "MDFriday Preview");
89+
body.append("license_key", licenseKey);
8990

9091
// 将 FormData 转换为 ArrayBuffer
9192
const boundary = "----WebKitFormBoundary" + Math.random().toString(36).substring(2, 9);
@@ -121,7 +122,7 @@ export class Hugoverse {
121122
* -F "size=12345" \
122123
* -F "asset=@/Users/weisun/Downloads/site.zip"
123124
*/
124-
async createMDFPreview(name:string, content:Uint8Array, type: 'share' | 'sub' = 'share', path:string = ''): Promise<string> {
125+
async createMDFPreview(name:string, content:Uint8Array, type: 'share' | 'sub' | 'custom' | 'enterprise' = 'share', path:string = ''): Promise<string> {
125126
try {
126127
const createResourceUrl = `${this.apiUrl}/api/mdf/preview?type=MDFPreview`;
127128

src/i18n/locales/en.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export const en: TranslationNamespace = {
112112
upgrade_for_mdfshare: "Please upgrade your plan to use MDFriday Share",
113113
upgrade_for_subdomain: "Please upgrade your plan to use MDFriday Subdomain",
114114
upgrade_for_custom_domain: "Please upgrade your plan to use MDFriday Custom Domain",
115+
upgrade_for_enterprise: "Please upgrade to Enterprise plan and configure enterprise server URL",
115116

116117
// Netlify settings
117118
netlify_settings: "Netlify Settings",
@@ -281,11 +282,13 @@ export const en: TranslationNamespace = {
281282
publish_option_mdfriday_share: "MDFriday Share",
282283
publish_option_mdfriday_app: "MDFriday Subdomain",
283284
publish_option_mdfriday_custom: "MDFriday Custom Domain",
285+
publish_option_mdfriday_enterprise: "MDFriday Enterprise",
284286
publish_option_netlify: "Netlify",
285287
publish_option_ftp: "FTP Upload",
286288
mdfriday_share_hint: "MDFriday Share allows you to share your site instantly. Your site will be published to your personal MDFriday space.",
287289
mdfriday_app_hint: "MDFriday Subdomain publishes your site to your personal subdomain. Your site will be available at your-subdomain.mdfriday.com.",
288290
mdfriday_custom_hint: "MDFriday Custom Domain publishes your site to your custom domain. Make sure DNS is configured correctly.",
291+
mdfriday_enterprise_hint: "MDFriday Enterprise publishes your site to your enterprise server. Make sure enterprise server URL is configured.",
289292
mdfriday_license_required: "This feature requires an activated license. Please activate your license in Settings.",
290293
publish_building: "Publishing...",
291294
publish_success: "Published successfully!",

src/i18n/locales/zh-cn.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export const zhCn: TranslationNamespace = {
112112
upgrade_for_mdfshare: "请升级您的套餐以使用 MDFriday 分享功能",
113113
upgrade_for_subdomain: "请升级您的套餐以使用 MDFriday 子域名功能",
114114
upgrade_for_custom_domain: "请升级您的套餐以使用 MDFriday 自定义域名功能",
115+
upgrade_for_enterprise: "请升级到企业版套餐并配置企业服务器地址",
115116

116117
// Netlify settings
117118
netlify_settings: "Netlify 设置",
@@ -272,11 +273,13 @@ export const zhCn: TranslationNamespace = {
272273
publish_option_mdfriday_share: "MDFriday 分享",
273274
publish_option_mdfriday_app: "MDFriday 子域名",
274275
publish_option_mdfriday_custom: "MDFriday 自定义域名",
276+
publish_option_mdfriday_enterprise: "MDFriday 企业版",
275277
publish_option_netlify: "Netlify",
276278
publish_option_ftp: "FTP 上传",
277279
mdfriday_share_hint: "MDFriday 分享允许您即时分享站点。您的站点将发布到您的个人 MDFriday 空间。",
278280
mdfriday_app_hint: "MDFriday 子域名将您的站点发布到个人子域名。您的站点将可通过 your-subdomain.mdfriday.com 访问。",
279281
mdfriday_custom_hint: "MDFriday 自定义域名将您的站点发布到您的自定义域名。请确保 DNS 已正确配置。",
282+
mdfriday_enterprise_hint: "MDFriday 企业版将您的站点发布到企业服务器。请确保已配置企业服务器地址。",
280283
mdfriday_license_required: "此功能需要激活许可证。请在设置中激活您的许可证。",
281284
publish_building: "正在发布...",
282285
publish_success: "发布成功!",

src/projects/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface ProjectLanguageContent {
99
}
1010

1111
export interface ProjectPublishConfig {
12-
method: 'netlify' | 'ftp' | 'mdf-share' | 'mdf-app';
12+
method: 'netlify' | 'ftp' | 'mdf-share' | 'mdf-app' | 'mdf-custom' | 'mdf-enterprise';
1313
netlify?: {
1414
accessToken?: string;
1515
projectId?: string;
@@ -64,7 +64,7 @@ export interface ProjectBuildHistory {
6464
timestamp: number;
6565
success: boolean;
6666
type: 'preview' | 'publish';
67-
publishMethod?: 'netlify' | 'ftp' | 'mdf-share' | 'mdf-app';
67+
publishMethod?: 'netlify' | 'ftp' | 'mdf-share' | 'mdf-app' | 'mdf-custom' | 'mdf-enterprise';
6868
url?: string;
6969
error?: string;
7070
previewId?: string; // Preview directory ID for exporting

src/svelte/Site.svelte

Lines changed: 87 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
let publishSuccess = false;
101101
let publishUrl = '';
102102
// Map 'mdfriday' from settings to 'netlify' as default (settings uses 'mdfriday' for display config)
103-
let selectedPublishOption: 'netlify' | 'ftp' | 'mdf-share' | 'mdf-app' | 'mdf-custom' =
103+
let selectedPublishOption: 'netlify' | 'ftp' | 'mdf-share' | 'mdf-app' | 'mdf-custom' | 'mdf-enterprise' =
104104
(plugin.settings.publishMethod === 'mdfriday' ? 'netlify' : plugin.settings.publishMethod) || 'netlify';
105105
106106
// Netlify configuration (project-specific)
@@ -133,6 +133,7 @@ let selectedPublishOption: 'netlify' | 'ftp' | 'mdf-share' | 'mdf-app' | 'mdf-cu
133133
let hasPublishPermission = false;
134134
let hasSubdomainPermission = false;
135135
let hasCustomDomainPermission = false;
136+
let hasEnterprisePermission = false;
136137
let publishOptions: Array<{ value: string; label: string }> = [];
137138
138139
// Reactive block to update license-related state (similar to theme selection at line 64-79)
@@ -145,28 +146,33 @@ let selectedPublishOption: 'netlify' | 'ftp' | 'mdf-share' | 'mdf-app' | 'mdf-cu
145146
146147
// Check feature permissions from license
147148
const features = plugin.settings.license?.features;
149+
const licenseplan = plugin.settings.license?.plan;
148150
hasPublishPermission = isLicenseActivated && features?.publish_enabled === true;
149151
hasSubdomainPermission = isLicenseActivated && features?.custom_sub_domain === true;
150152
hasCustomDomainPermission = isLicenseActivated && features?.custom_domain === true;
153+
hasEnterprisePermission = isLicenseActivated && licenseplan === 'enterprise' && !!plugin.settings.enterpriseServerUrl;
151154
152-
// Update publish options - MDFriday Share, MDFriday Subdomain, and MDFriday Custom Domain are always shown
155+
// Update publish options - MDFriday Share, MDFriday Subdomain, MDFriday Custom Domain, and MDFriday Enterprise are always shown
153156
publishOptions = [
154157
{ value: 'netlify', label: t('ui.publish_option_netlify') },
155158
{ value: 'ftp', label: t('ui.publish_option_ftp') },
156159
{ value: 'mdf-share', label: t('ui.publish_option_mdfriday_share') },
157160
{ value: 'mdf-app', label: t('ui.publish_option_mdfriday_app') },
158161
{ value: 'mdf-custom', label: t('ui.publish_option_mdfriday_custom') },
162+
{ value: 'mdf-enterprise', label: t('ui.publish_option_mdfriday_enterprise') },
159163
];
160164
}
161165
162166
// Check if current publish option requires license and permissions
163167
$: requiresPublishPermission = selectedPublishOption === 'mdf-share';
164168
$: requiresSubdomainPermission = selectedPublishOption === 'mdf-app';
165169
$: requiresCustomDomainPermission = selectedPublishOption === 'mdf-custom';
170+
$: requiresEnterprisePermission = selectedPublishOption === 'mdf-enterprise';
166171
$: isPublishDisabled =
167172
(requiresPublishPermission && !hasPublishPermission) ||
168173
(requiresSubdomainPermission && !hasSubdomainPermission) ||
169-
(requiresCustomDomainPermission && !hasCustomDomainPermission);
174+
(requiresCustomDomainPermission && !hasCustomDomainPermission) ||
175+
(requiresEnterprisePermission && !hasEnterprisePermission);
170176
171177
// HTTP server related
172178
let httpServer: IncrementalBuildCoordinator;
@@ -1236,7 +1242,8 @@ let selectedPublishOption: 'netlify' | 'ftp' | 'mdf-share' | 'mdf-app' | 'mdf-cu
12361242
publishProgress = 80;
12371243
12381244
// Step 3: Deploy the preview (80-100%)
1239-
const deployPath = await plugin.hugoverse.deployMDFridayPreview(previewApiId);
1245+
const licenseKey = plugin.settings.license?.key || '';
1246+
const deployPath = await plugin.hugoverse.deployMDFridayPreview(previewApiId, licenseKey);
12401247
if (!deployPath) {
12411248
throw new Error('Failed to deploy MDFriday preview');
12421249
}
@@ -1281,7 +1288,8 @@ let selectedPublishOption: 'netlify' | 'ftp' | 'mdf-share' | 'mdf-app' | 'mdf-cu
12811288
publishProgress = 80;
12821289
12831290
// Step 3: Deploy the preview (80-100%)
1284-
const deployPath = await plugin.hugoverse.deployMDFridayPreview(previewApiId);
1291+
const licenseKey = plugin.settings.license?.key || '';
1292+
const deployPath = await plugin.hugoverse.deployMDFridayPreview(previewApiId, licenseKey);
12851293
if (!deployPath) {
12861294
throw new Error('Failed to deploy MDFriday Subdomain');
12871295
}
@@ -1330,7 +1338,8 @@ let selectedPublishOption: 'netlify' | 'ftp' | 'mdf-share' | 'mdf-app' | 'mdf-cu
13301338
publishProgress = 80;
13311339
13321340
// Step 3: Deploy the preview (80-100%)
1333-
const deployPath = await plugin.hugoverse.deployMDFridayPreview(previewApiId);
1341+
const licenseKey = plugin.settings.license?.key || '';
1342+
const deployPath = await plugin.hugoverse.deployMDFridayPreview(previewApiId, licenseKey);
13341343
if (!deployPath) {
13351344
throw new Error('Failed to deploy MDFriday Custom Domain');
13361345
}
@@ -1369,6 +1378,64 @@ let selectedPublishOption: 'netlify' | 'ftp' | 'mdf-share' | 'mdf-app' | 'mdf-cu
13691378
plugin.hugoverse.sendCounter('mdf-custom').catch(error => {
13701379
console.warn('Counter request failed (non-critical):', error);
13711380
});
1381+
} else if (selectedPublishOption === 'mdf-enterprise') {
1382+
// MDFriday Enterprise deployment
1383+
const zipContent = await createZipFromDirectory(publicDir);
1384+
publishProgress = 50;
1385+
1386+
// MDFriday Enterprise uses sitePath as name and type 'enterprise'
1387+
const previewApiId = await plugin.hugoverse.createMDFPreview(previewId, zipContent, 'enterprise', sitePath);
1388+
if (!previewApiId) {
1389+
throw new Error('Failed to create MDFriday Enterprise preview');
1390+
}
1391+
publishProgress = 80;
1392+
1393+
// Step 3: Deploy the preview (80-100%) with license key
1394+
const licenseKey = plugin.settings.license?.key || '';
1395+
const deployPath = await plugin.hugoverse.deployMDFridayPreview(previewApiId, licenseKey);
1396+
if (!deployPath) {
1397+
throw new Error('Failed to deploy MDFriday Enterprise');
1398+
}
1399+
publishProgress = 100;
1400+
1401+
// Step 4: Construct final publish URL for MDFriday Enterprise
1402+
// Use enterprise server URL from settings
1403+
const enterpriseServerUrl = plugin.settings.enterpriseServerUrl;
1404+
if (!enterpriseServerUrl) {
1405+
throw new Error('Enterprise server URL not configured');
1406+
}
1407+
// Extract main domain from URL (e.g., mdfriday.sunwei.xyz -> sunwei.xyz)
1408+
const fullHost = enterpriseServerUrl.replace(/^https?:\/\//, '').replace(/\/$/, '');
1409+
const hostParts = fullHost.split('.');
1410+
// Get last 2 parts (domain.tld), e.g., sunwei.xyz
1411+
const host = hostParts.length >= 2 ? hostParts.slice(-2).join('.') : fullHost;
1412+
const basePath = deployPath.startsWith('/') ? deployPath : `/${deployPath}`;
1413+
const normalizedPath = basePath === '/' ? '' : basePath;
1414+
publishUrl = `https://${host}${normalizedPath}`;
1415+
publishSuccess = true;
1416+
1417+
new Notice(t('messages.site_published_successfully'), 3000);
1418+
1419+
// Save project configuration and add build history
1420+
await saveCurrentProjectConfiguration();
1421+
if (currentContents.length > 0 && siteName) {
1422+
const projectId = getProjectId();
1423+
if (projectId) {
1424+
await plugin.projectService.addBuildHistory({
1425+
projectId: projectId,
1426+
timestamp: Date.now(),
1427+
success: true,
1428+
type: 'publish',
1429+
publishMethod: 'mdf-enterprise',
1430+
url: publishUrl
1431+
});
1432+
}
1433+
}
1434+
1435+
// Send counter for publish (don't wait for result)
1436+
plugin.hugoverse.sendCounter('mdf-enterprise').catch(error => {
1437+
console.warn('Counter request failed (non-critical):', error);
1438+
});
13721439
}
13731440
13741441
} catch (error) {
@@ -2629,6 +2696,20 @@ let selectedPublishOption: 'netlify' | 'ftp' | 'mdf-share' | 'mdf-app' | 'mdf-cu
26292696
</div>
26302697
{/if}
26312698

2699+
<!-- MDFriday Enterprise Info -->
2700+
{#if selectedPublishOption === 'mdf-enterprise'}
2701+
<div class="publish-config">
2702+
<div class="field-hint">
2703+
{t('ui.mdfriday_enterprise_hint')}
2704+
</div>
2705+
{#if !hasEnterprisePermission}
2706+
<div class="license-warning">
2707+
⚠️ {t('settings.upgrade_for_enterprise')}
2708+
</div>
2709+
{/if}
2710+
</div>
2711+
{/if}
2712+
26322713
<!-- Publish Button -->
26332714
<div class="publish-actions">
26342715
{#if isPublishing}

0 commit comments

Comments
 (0)