dotshare-cli 1.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -21
- package/README.md +245 -189
- package/SECURITY.md +145 -0
- package/bin/dotshare-agent.js +7 -0
- package/bin/dotshare-cli.js +11 -7
- package/bin/dotshare-mcp.js +6 -0
- package/docs/AGENT_INTEGRATION.md +541 -0
- package/out/agent/commands.js +119 -0
- package/out/agent/server.js +97 -0
- package/out/cli/commands.js +128 -376
- package/package.json +34 -94
- package/bin/dotshare-scheduler.js +0 -208
- package/out/analytics.js +0 -67
- package/out/analytics.js.map +0 -1
- package/out/bluesky.js +0 -100
- package/out/bluesky.js.map +0 -1
- package/out/cli/commands.js.map +0 -1
- package/out/cli/config.js +0 -144
- package/out/cli/config.js.map +0 -1
- package/out/credential-provider.js +0 -92
- package/out/credential-provider.js.map +0 -1
- package/out/discord.js +0 -85
- package/out/discord.js.map +0 -1
- package/out/extension.js +0 -1383
- package/out/extension.js.map +0 -1
- package/out/facebook.js +0 -66
- package/out/facebook.js.map +0 -1
- package/out/gemini.js +0 -219
- package/out/gemini.js.map +0 -1
- package/out/linkedin.js +0 -110
- package/out/linkedin.js.map +0 -1
- package/out/message-handlers.js +0 -391
- package/out/message-handlers.js.map +0 -1
- package/out/openai.js +0 -217
- package/out/openai.js.map +0 -1
- package/out/post-executor.js +0 -168
- package/out/post-executor.js.map +0 -1
- package/out/reddit.js +0 -538
- package/out/reddit.js.map +0 -1
- package/out/scheduled-posts.js +0 -100
- package/out/scheduled-posts.js.map +0 -1
- package/out/scheduler.js +0 -98
- package/out/scheduler.js.map +0 -1
- package/out/storage-manager.js +0 -403
- package/out/storage-manager.js.map +0 -1
- package/out/telegram.js +0 -104
- package/out/telegram.js.map +0 -1
- package/out/types.js +0 -3
- package/out/types.js.map +0 -1
- package/out/webview-provider.js +0 -168
- package/out/webview-provider.js.map +0 -1
- package/out/x.js +0 -55
- package/out/x.js.map +0 -1
- package/out/xai.js +0 -235
- package/out/xai.js.map +0 -1
- package/src/cli/commands.ts +0 -380
- package/src/cli/config.ts +0 -148
package/out/extension.js
DELETED
|
@@ -1,1383 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.deactivate = exports.activate = void 0;
|
|
27
|
-
const vscode = __importStar(require("vscode"));
|
|
28
|
-
const fs = __importStar(require("fs"));
|
|
29
|
-
const path = __importStar(require("path"));
|
|
30
|
-
const os = __importStar(require("os"));
|
|
31
|
-
// Basic imports needed for current functionality
|
|
32
|
-
const gemini_1 = require("./gemini");
|
|
33
|
-
const openai_1 = require("./openai");
|
|
34
|
-
const xai_1 = require("./xai");
|
|
35
|
-
const scheduled_posts_1 = require("./scheduled-posts");
|
|
36
|
-
const scheduler_1 = require("./scheduler");
|
|
37
|
-
function activate(context) {
|
|
38
|
-
console.log('DotShare extension is now active!');
|
|
39
|
-
// Command for generating post
|
|
40
|
-
const generateDisposable = vscode.commands.registerCommand('dotshare.generatePost', () => {
|
|
41
|
-
vscode.window.showInformationMessage('Please use the DotShare activity bar panel to enter API keys and generate posts.');
|
|
42
|
-
});
|
|
43
|
-
// Command for LinkedIn
|
|
44
|
-
const linkedinDisposable = vscode.commands.registerCommand('dotshare.shareToLinkedIn', () => {
|
|
45
|
-
vscode.window.showInformationMessage('Please use the DotShare activity bar panel to share to LinkedIn.');
|
|
46
|
-
});
|
|
47
|
-
// Command for Telegram
|
|
48
|
-
const telegramDisposable = vscode.commands.registerCommand('dotshare.shareToTelegram', () => {
|
|
49
|
-
vscode.window.showInformationMessage('Please use the DotShare activity bar panel to share to Telegram.');
|
|
50
|
-
});
|
|
51
|
-
context.subscriptions.push(generateDisposable);
|
|
52
|
-
context.subscriptions.push(linkedinDisposable);
|
|
53
|
-
context.subscriptions.push(telegramDisposable);
|
|
54
|
-
// Register webview provider
|
|
55
|
-
context.subscriptions.push(vscode.window.registerWebviewViewProvider(DotShareProvider.viewType, new DotShareProvider(context.extensionUri, context)));
|
|
56
|
-
}
|
|
57
|
-
exports.activate = activate;
|
|
58
|
-
class DotShareProvider {
|
|
59
|
-
constructor(_extensionUri, _context) {
|
|
60
|
-
this._extensionUri = _extensionUri;
|
|
61
|
-
this._context = _context;
|
|
62
|
-
// Initialize scheduled posts storage synchronously
|
|
63
|
-
this.initializeStorage();
|
|
64
|
-
}
|
|
65
|
-
initializeStorage() {
|
|
66
|
-
// Try to get global storage first
|
|
67
|
-
const storageUri = this._context.globalStorageUri;
|
|
68
|
-
let storagePath;
|
|
69
|
-
if (storageUri) {
|
|
70
|
-
storagePath = storageUri.fsPath;
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
// Fallback to extension storage directory
|
|
74
|
-
storagePath = path.join(this._context.extensionPath, 'storage');
|
|
75
|
-
}
|
|
76
|
-
// Try to create the storage directory synchronously
|
|
77
|
-
try {
|
|
78
|
-
if (!fs.existsSync(storagePath)) {
|
|
79
|
-
fs.mkdirSync(storagePath, { recursive: true });
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
console.warn('Could not create storage directory, using temp:', error);
|
|
84
|
-
// Final fallback to temp directory
|
|
85
|
-
storagePath = path.join(os.tmpdir(), 'dotshare-scheduled');
|
|
86
|
-
try {
|
|
87
|
-
if (!fs.existsSync(storagePath)) {
|
|
88
|
-
fs.mkdirSync(storagePath, { recursive: true });
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
catch (tempError) {
|
|
92
|
-
console.error('Even temp directory creation failed:', tempError);
|
|
93
|
-
// Last resort - use system temp
|
|
94
|
-
storagePath = os.tmpdir();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
this._scheduledPostsStorage = new scheduled_posts_1.ScheduledPostsStorage(storagePath);
|
|
98
|
-
}
|
|
99
|
-
resolveWebviewView(webviewView, context, token) {
|
|
100
|
-
void context; // Suppress unused parameter warning
|
|
101
|
-
void token; // Suppress unused parameter warning
|
|
102
|
-
this._view = webviewView;
|
|
103
|
-
webviewView.webview.options = {
|
|
104
|
-
enableScripts: true,
|
|
105
|
-
localResourceRoots: [this._extensionUri]
|
|
106
|
-
};
|
|
107
|
-
webviewView.webview.html = this._getHtmlForWebview(webviewView.webview);
|
|
108
|
-
// Load initial data when webview is ready
|
|
109
|
-
setImmediate(async () => {
|
|
110
|
-
try {
|
|
111
|
-
// Load scheduled posts
|
|
112
|
-
await this._loadScheduledPosts(webviewView);
|
|
113
|
-
// Load post history and analytics
|
|
114
|
-
await this._loadPostHistory(webviewView);
|
|
115
|
-
// Load all saved configuration (tokens, model settings, etc.)
|
|
116
|
-
await this._loadConfiguration(webviewView);
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
console.error('Error loading initial data:', error);
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
webviewView.webview.onDidReceiveMessage(async (message) => {
|
|
123
|
-
switch (message.command) {
|
|
124
|
-
case 'generatePost':
|
|
125
|
-
if (!message.selectedModel || !message.selectedModel.apiKey) {
|
|
126
|
-
vscode.window.showErrorMessage('API Key is required to generate posts.');
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
try {
|
|
130
|
-
const { provider, apiKey, model } = message.selectedModel;
|
|
131
|
-
let post = null;
|
|
132
|
-
// Retry logic for API failures
|
|
133
|
-
let retryCount = 0;
|
|
134
|
-
const maxRetries = 1;
|
|
135
|
-
while (retryCount <= maxRetries) {
|
|
136
|
-
try {
|
|
137
|
-
if (provider === 'gemini') {
|
|
138
|
-
post = await (0, gemini_1.generatePost)(apiKey, model);
|
|
139
|
-
}
|
|
140
|
-
else if (provider === 'openai') {
|
|
141
|
-
post = await (0, openai_1.generatePost)(apiKey, model);
|
|
142
|
-
}
|
|
143
|
-
else if (provider === 'xai') {
|
|
144
|
-
post = await (0, xai_1.generatePost)(apiKey, model);
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
webviewView.webview.postMessage({ command: 'status', status: 'Error: Unsupported AI provider.', type: 'error' });
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
break; // Success, exit retry loop
|
|
151
|
-
}
|
|
152
|
-
catch (retryError) {
|
|
153
|
-
retryCount++;
|
|
154
|
-
if (retryCount > maxRetries) {
|
|
155
|
-
throw retryError; // Re-throw after max retries
|
|
156
|
-
}
|
|
157
|
-
// Wait briefly before retry
|
|
158
|
-
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
if (post) {
|
|
162
|
-
// Save post to history with AI metadata
|
|
163
|
-
this._savePostToHistory(provider, model, post);
|
|
164
|
-
webviewView.webview.postMessage({ command: 'updatePost', post: post.text });
|
|
165
|
-
// Refresh analytics after posting
|
|
166
|
-
const updatedAnalytics = this._calculateAnalytics();
|
|
167
|
-
webviewView.webview.postMessage({
|
|
168
|
-
command: 'updateAnalytics',
|
|
169
|
-
analytics: updatedAnalytics
|
|
170
|
-
});
|
|
171
|
-
// Securely store API keys and save model selection for persistence
|
|
172
|
-
if (message.selectedModel) {
|
|
173
|
-
await this._context.secrets.store(`${message.selectedModel.provider}ApiKey`, message.selectedModel.apiKey);
|
|
174
|
-
// Also save model selection (without API key for security)
|
|
175
|
-
const modelForStorage = { provider, model, apiKey: '' };
|
|
176
|
-
this._context.globalState.update('selectedModel', modelForStorage);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
catch (error) {
|
|
181
|
-
const errorMessageObj = error instanceof Error ? error : { message: String(error) };
|
|
182
|
-
let errorMessage = 'Error generating post.';
|
|
183
|
-
if (errorMessageObj.message.includes('API key')) {
|
|
184
|
-
errorMessage = 'Invalid API key. Check your credentials.';
|
|
185
|
-
}
|
|
186
|
-
else if (errorMessageObj.message.includes('rate limit')) {
|
|
187
|
-
errorMessage = 'API rate limit exceeded. Try again later.';
|
|
188
|
-
}
|
|
189
|
-
else if (errorMessageObj.message.includes('network')) {
|
|
190
|
-
errorMessage = 'Network error. Check your connection.';
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
errorMessage = `AI service error: ${errorMessageObj.message}`;
|
|
194
|
-
}
|
|
195
|
-
webviewView.webview.postMessage({ command: 'status', status: errorMessage, type: 'error' });
|
|
196
|
-
}
|
|
197
|
-
return;
|
|
198
|
-
case 'saveModelSelection':
|
|
199
|
-
if (message.selectedModel) {
|
|
200
|
-
// Store selected model without API key for security
|
|
201
|
-
const modelForStorage = { ...message.selectedModel, apiKey: '' };
|
|
202
|
-
this._context.globalState.update('selectedModel', modelForStorage);
|
|
203
|
-
}
|
|
204
|
-
return;
|
|
205
|
-
case 'saveLinkedinToken':
|
|
206
|
-
try {
|
|
207
|
-
await this._context.secrets.store('linkedinToken', message.linkedinToken || '');
|
|
208
|
-
webviewView.webview.postMessage({ command: 'status', status: 'LinkedIn token saved!', type: 'success' });
|
|
209
|
-
}
|
|
210
|
-
catch (error) {
|
|
211
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
212
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error saving LinkedIn token: ${errorMessage}`, type: 'error' });
|
|
213
|
-
}
|
|
214
|
-
return;
|
|
215
|
-
case 'saveTelegramCredentials':
|
|
216
|
-
try {
|
|
217
|
-
await this._context.secrets.store('telegramBot', message.telegramBot || '');
|
|
218
|
-
await this._context.secrets.store('telegramChat', message.telegramChat || '');
|
|
219
|
-
webviewView.webview.postMessage({ command: 'status', status: 'Telegram credentials saved!', type: 'success' });
|
|
220
|
-
}
|
|
221
|
-
catch (error) {
|
|
222
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
223
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error saving Telegram credentials: ${errorMessage}`, type: 'error' });
|
|
224
|
-
}
|
|
225
|
-
return;
|
|
226
|
-
case 'saveFacebookToken': {
|
|
227
|
-
try {
|
|
228
|
-
await this._context.secrets.store('facebookToken', message.facebookToken || '');
|
|
229
|
-
await this._context.secrets.store('facebookPageToken', message.facebookPageToken || '');
|
|
230
|
-
await this._context.secrets.store('facebookPageId', message.facebookPageId || '');
|
|
231
|
-
webviewView.webview.postMessage({ command: 'status', status: 'Facebook credentials saved!', type: 'success' });
|
|
232
|
-
}
|
|
233
|
-
catch (error) {
|
|
234
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error saving Facebook credentials: ${error}`, type: 'error' });
|
|
235
|
-
}
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
case 'saveDiscordWebhook': {
|
|
239
|
-
try {
|
|
240
|
-
await this._context.secrets.store('discordWebhook', message.discordWebhookUrl || '');
|
|
241
|
-
webviewView.webview.postMessage({ command: 'status', status: 'Discord webhook saved!', type: 'success' });
|
|
242
|
-
}
|
|
243
|
-
catch (error) {
|
|
244
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error saving Discord webhook: ${error}`, type: 'error' });
|
|
245
|
-
}
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
case 'saveXCredentials': {
|
|
249
|
-
try {
|
|
250
|
-
await this._context.secrets.store('xAccessToken', message.xAccessToken || '');
|
|
251
|
-
await this._context.secrets.store('xAccessSecret', message.xAccessSecret || '');
|
|
252
|
-
webviewView.webview.postMessage({ command: 'status', status: 'X/Twitter credentials saved!', type: 'success' });
|
|
253
|
-
}
|
|
254
|
-
catch (error) {
|
|
255
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error saving X/Twitter credentials: ${error}`, type: 'error' });
|
|
256
|
-
}
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
case 'saveRedditCredentials': {
|
|
260
|
-
try {
|
|
261
|
-
await this._context.secrets.store('redditAccessToken', message.redditAccessToken || '');
|
|
262
|
-
await this._context.secrets.store('redditRefreshToken', message.redditRefreshToken || '');
|
|
263
|
-
webviewView.webview.postMessage({ command: 'status', status: 'Reddit credentials saved!', type: 'success' });
|
|
264
|
-
}
|
|
265
|
-
catch (error) {
|
|
266
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error saving Reddit credentials: ${error}`, type: 'error' });
|
|
267
|
-
}
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
case 'saveBlueSkyCredentials': {
|
|
271
|
-
try {
|
|
272
|
-
await this._context.secrets.store('blueskyIdentifier', message.blueskyIdentifier || '');
|
|
273
|
-
await this._context.secrets.store('blueskyPassword', message.blueskyPassword || '');
|
|
274
|
-
webviewView.webview.postMessage({ command: 'status', status: 'BlueSky credentials saved!', type: 'success' });
|
|
275
|
-
}
|
|
276
|
-
catch (error) {
|
|
277
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error saving BlueSky credentials: ${error}`, type: 'error' });
|
|
278
|
-
}
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
case 'loadConfiguration': {
|
|
282
|
-
const savedModel = this._context.globalState.get('selectedModel');
|
|
283
|
-
let apiKey = '';
|
|
284
|
-
if (savedModel && typeof savedModel === 'object' && 'provider' in savedModel && typeof savedModel.provider === 'string') {
|
|
285
|
-
const validModel = savedModel;
|
|
286
|
-
apiKey = await this._context.secrets.get(`${validModel.provider}ApiKey`) || '';
|
|
287
|
-
}
|
|
288
|
-
// Get all social media tokens from secrets
|
|
289
|
-
const savedLinkedInToken = await this._context.secrets.get('linkedinToken') || '';
|
|
290
|
-
const savedTelegramBot = await this._context.secrets.get('telegramBot') || '';
|
|
291
|
-
const savedTelegramChat = await this._context.secrets.get('telegramChat') || '';
|
|
292
|
-
const savedXToken = await this._context.secrets.get('xAccessToken') || '';
|
|
293
|
-
const savedXSecret = await this._context.secrets.get('xAccessSecret') || '';
|
|
294
|
-
const savedFacebookToken = await this._context.secrets.get('facebookToken') || '';
|
|
295
|
-
const savedFacebookPageToken = await this._context.secrets.get('facebookPageToken') || '';
|
|
296
|
-
const savedFacebookPageId = await this._context.secrets.get('facebookPageId') || '';
|
|
297
|
-
const savedDiscordWebhook = await this._context.secrets.get('discordWebhook') || '';
|
|
298
|
-
const savedRedditToken = await this._context.secrets.get('redditAccessToken') || '';
|
|
299
|
-
const savedRedditRefresh = await this._context.secrets.get('redditRefreshToken') || '';
|
|
300
|
-
// Load Reddit configuration details
|
|
301
|
-
const savedRedditClientId = await this._context.secrets.get('redditClientId') || '';
|
|
302
|
-
const savedRedditClientSecret = await this._context.secrets.get('redditClientSecret') || '';
|
|
303
|
-
const savedRedditUsername = await this._context.secrets.get('redditUsername') || '';
|
|
304
|
-
const savedRedditPassword = await this._context.secrets.get('redditPassword') || '';
|
|
305
|
-
const savedRedditApiName = this._context.globalState.get('redditApiName', 'Reddit Account');
|
|
306
|
-
const savedBlueSkyIdentifier = await this._context.secrets.get('blueskyIdentifier') || '';
|
|
307
|
-
const savedBlueSkyPassword = await this._context.secrets.get('blueskyPassword') || '';
|
|
308
|
-
webviewView.webview.postMessage({
|
|
309
|
-
command: 'updateConfiguration',
|
|
310
|
-
selectedModel: savedModel ? { ...savedModel, apiKey } : savedModel,
|
|
311
|
-
linkedinToken: savedLinkedInToken,
|
|
312
|
-
telegramBot: savedTelegramBot,
|
|
313
|
-
telegramChat: savedTelegramChat,
|
|
314
|
-
xAccessToken: savedXToken,
|
|
315
|
-
xAccessSecret: savedXSecret,
|
|
316
|
-
facebookToken: savedFacebookToken,
|
|
317
|
-
facebookPageToken: savedFacebookPageToken,
|
|
318
|
-
facebookPageId: savedFacebookPageId,
|
|
319
|
-
discordWebhookUrl: savedDiscordWebhook,
|
|
320
|
-
redditAccessToken: savedRedditToken,
|
|
321
|
-
redditRefreshToken: savedRedditRefresh,
|
|
322
|
-
redditClientId: savedRedditClientId,
|
|
323
|
-
redditClientSecret: savedRedditClientSecret,
|
|
324
|
-
redditUsername: savedRedditUsername,
|
|
325
|
-
redditPassword: savedRedditPassword,
|
|
326
|
-
redditApiName: savedRedditApiName,
|
|
327
|
-
blueskyIdentifier: savedBlueSkyIdentifier,
|
|
328
|
-
blueskyPassword: savedBlueSkyPassword
|
|
329
|
-
});
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
case 'shareToFacebook': {
|
|
333
|
-
try {
|
|
334
|
-
const facebookPost = this._context.globalState.get('lastPost');
|
|
335
|
-
if (!facebookPost) {
|
|
336
|
-
webviewView.webview.postMessage({ command: 'status', status: 'Error: No post generated. Generate first.', type: 'error' });
|
|
337
|
-
return;
|
|
338
|
-
}
|
|
339
|
-
const history = this._context.globalState.get('postHistory', []);
|
|
340
|
-
const mostRecentPost = history[0];
|
|
341
|
-
const postId = mostRecentPost?.id;
|
|
342
|
-
await this.shareToFacebookWithUpdate(webviewView, facebookPost, message, postId);
|
|
343
|
-
}
|
|
344
|
-
catch (error) {
|
|
345
|
-
const history = this._context.globalState.get('postHistory', []);
|
|
346
|
-
const mostRecentPost = history[0];
|
|
347
|
-
const postId = mostRecentPost?.id;
|
|
348
|
-
if (postId) {
|
|
349
|
-
this._recordShare(postId, 'facebook', false, String(error));
|
|
350
|
-
}
|
|
351
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error sharing to Facebook: ${error}`, type: 'error' });
|
|
352
|
-
}
|
|
353
|
-
return;
|
|
354
|
-
}
|
|
355
|
-
case 'shareToDiscord': {
|
|
356
|
-
try {
|
|
357
|
-
const discordPost = this._context.globalState.get('lastPost');
|
|
358
|
-
if (!discordPost) {
|
|
359
|
-
webviewView.webview.postMessage({ command: 'status', status: 'Error: No post generated. Generate first.', type: 'error' });
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
const history = this._context.globalState.get('postHistory', []);
|
|
363
|
-
const mostRecentPost = history[0];
|
|
364
|
-
const postId = mostRecentPost?.id;
|
|
365
|
-
await this.shareToDiscordWithUpdate(webviewView, discordPost, message, postId);
|
|
366
|
-
}
|
|
367
|
-
catch (error) {
|
|
368
|
-
const history = this._context.globalState.get('postHistory', []);
|
|
369
|
-
const mostRecentPost = history[0];
|
|
370
|
-
const postId = mostRecentPost?.id;
|
|
371
|
-
if (postId) {
|
|
372
|
-
this._recordShare(postId, 'discord', false, String(error));
|
|
373
|
-
}
|
|
374
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error sharing to Discord: ${error}`, type: 'error' });
|
|
375
|
-
}
|
|
376
|
-
return;
|
|
377
|
-
}
|
|
378
|
-
case 'shareToX': {
|
|
379
|
-
try {
|
|
380
|
-
const xPost = this._context.globalState.get('lastPost');
|
|
381
|
-
if (!xPost) {
|
|
382
|
-
webviewView.webview.postMessage({ command: 'status', status: 'Error: No post generated. Generate first.', type: 'error' });
|
|
383
|
-
return;
|
|
384
|
-
}
|
|
385
|
-
const history = this._context.globalState.get('postHistory', []);
|
|
386
|
-
const mostRecentPost = history[0];
|
|
387
|
-
const postId = mostRecentPost?.id;
|
|
388
|
-
await this.shareToXWithUpdate(webviewView, xPost, message, postId);
|
|
389
|
-
}
|
|
390
|
-
catch (error) {
|
|
391
|
-
const history = this._context.globalState.get('postHistory', []);
|
|
392
|
-
const mostRecentPost = history[0];
|
|
393
|
-
const postId = mostRecentPost?.id;
|
|
394
|
-
if (postId) {
|
|
395
|
-
this._recordShare(postId, 'x', false, String(error));
|
|
396
|
-
}
|
|
397
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error sharing to X/Twitter: ${error}`, type: 'error' });
|
|
398
|
-
}
|
|
399
|
-
return;
|
|
400
|
-
}
|
|
401
|
-
case 'shareToReddit': {
|
|
402
|
-
try {
|
|
403
|
-
const msg = message;
|
|
404
|
-
const postText = msg.post || '';
|
|
405
|
-
const mediaPaths = msg.mediaFilePaths || [];
|
|
406
|
-
const redditPost = {
|
|
407
|
-
text: postText,
|
|
408
|
-
media: mediaPaths
|
|
409
|
-
};
|
|
410
|
-
await this.shareToRedditWithUpdate(webviewView, redditPost, message, undefined);
|
|
411
|
-
}
|
|
412
|
-
catch (error) {
|
|
413
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error sharing to Reddit: ${error}`, type: 'error' });
|
|
414
|
-
}
|
|
415
|
-
return;
|
|
416
|
-
}
|
|
417
|
-
case 'shareToLinkedIn': {
|
|
418
|
-
try {
|
|
419
|
-
const msg = message;
|
|
420
|
-
const postText = msg.post || '';
|
|
421
|
-
const mediaPaths = msg.mediaFilePaths || [];
|
|
422
|
-
const linkedinPost = {
|
|
423
|
-
text: postText,
|
|
424
|
-
media: mediaPaths
|
|
425
|
-
};
|
|
426
|
-
await this.shareToLinkedInWithUpdate(webviewView, linkedinPost, message, undefined);
|
|
427
|
-
}
|
|
428
|
-
catch (error) {
|
|
429
|
-
const history = this._context.globalState.get('postHistory', []);
|
|
430
|
-
const mostRecentPost = history[0];
|
|
431
|
-
const postId = mostRecentPost?.id;
|
|
432
|
-
if (postId) {
|
|
433
|
-
this._recordShare(postId, 'linkedin', false, String(error));
|
|
434
|
-
}
|
|
435
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error sharing to LinkedIn: ${error}`, type: 'error' });
|
|
436
|
-
}
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
case 'shareToTelegram': {
|
|
440
|
-
try {
|
|
441
|
-
const msg = message;
|
|
442
|
-
const postText = msg.post || '';
|
|
443
|
-
const mediaPaths = msg.mediaFilePaths || [];
|
|
444
|
-
const telegramPost = {
|
|
445
|
-
text: postText,
|
|
446
|
-
media: mediaPaths
|
|
447
|
-
};
|
|
448
|
-
await this.shareToTelegramWithUpdate(webviewView, telegramPost, message, undefined);
|
|
449
|
-
}
|
|
450
|
-
catch (error) {
|
|
451
|
-
const history = this._context.globalState.get('postHistory', []);
|
|
452
|
-
const mostRecentPost = history[0];
|
|
453
|
-
const postId = mostRecentPost?.id;
|
|
454
|
-
if (postId) {
|
|
455
|
-
this._recordShare(postId, 'telegram', false, String(error));
|
|
456
|
-
}
|
|
457
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error sharing to Telegram: ${error}`, type: 'error' });
|
|
458
|
-
}
|
|
459
|
-
return;
|
|
460
|
-
}
|
|
461
|
-
case 'shareToBlueSky': {
|
|
462
|
-
try {
|
|
463
|
-
const blueskyPost = this._context.globalState.get('lastPost');
|
|
464
|
-
if (!blueskyPost) {
|
|
465
|
-
webviewView.webview.postMessage({ command: 'status', status: 'Error: No post generated. Generate first.', type: 'error' });
|
|
466
|
-
return;
|
|
467
|
-
}
|
|
468
|
-
const history = this._context.globalState.get('postHistory', []);
|
|
469
|
-
const mostRecentPost = history[0];
|
|
470
|
-
const postId = mostRecentPost?.id;
|
|
471
|
-
await this.shareToBlueSkyWithUpdate(webviewView, blueskyPost, message, postId);
|
|
472
|
-
}
|
|
473
|
-
catch (error) {
|
|
474
|
-
const history = this._context.globalState.get('postHistory', []);
|
|
475
|
-
const mostRecentPost = history[0];
|
|
476
|
-
const postId = mostRecentPost?.id;
|
|
477
|
-
if (postId) {
|
|
478
|
-
this._recordShare(postId, 'bluesky', false, String(error));
|
|
479
|
-
}
|
|
480
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error sharing to BlueSky: ${error}`, type: 'error' });
|
|
481
|
-
}
|
|
482
|
-
return;
|
|
483
|
-
}
|
|
484
|
-
case 'generateRedditTokens': {
|
|
485
|
-
try {
|
|
486
|
-
// Validate all required Reddit credentials
|
|
487
|
-
if (!message.redditClientId || !message.redditClientSecret ||
|
|
488
|
-
!message.redditUsername || !message.redditPassword ||
|
|
489
|
-
message.redditClientId.trim() === '' || message.redditClientSecret.trim() === '' ||
|
|
490
|
-
message.redditUsername.trim() === '' || message.redditPassword.trim() === '') {
|
|
491
|
-
webviewView.webview.postMessage({
|
|
492
|
-
command: 'status',
|
|
493
|
-
status: 'All Reddit credentials are required. Please fill in Client ID, Secret, Username, and Password.',
|
|
494
|
-
type: 'error'
|
|
495
|
-
});
|
|
496
|
-
return;
|
|
497
|
-
}
|
|
498
|
-
// Get current saved configuration for comparison
|
|
499
|
-
const savedClientId = await this._context.secrets.get('redditClientId') || '';
|
|
500
|
-
const savedClientSecret = await this._context.secrets.get('redditClientSecret') || '';
|
|
501
|
-
const savedUsername = await this._context.secrets.get('redditUsername') || '';
|
|
502
|
-
const savedPassword = await this._context.secrets.get('redditPassword') || '';
|
|
503
|
-
const savedApiName = this._context.globalState.get('redditApiName', '');
|
|
504
|
-
const savedAccessToken = await this._context.secrets.get('redditAccessToken') || '';
|
|
505
|
-
const currentClientId = message.redditClientId.trim();
|
|
506
|
-
const currentClientSecret = message.redditClientSecret.trim();
|
|
507
|
-
const currentUsername = message.redditUsername.trim();
|
|
508
|
-
const currentPassword = message.redditPassword.trim();
|
|
509
|
-
const currentApiName = message.redditApiName || 'Reddit Account';
|
|
510
|
-
// Check if configuration has changed or token needs regeneration
|
|
511
|
-
const configChanged = (savedClientId !== currentClientId ||
|
|
512
|
-
savedClientSecret !== currentClientSecret ||
|
|
513
|
-
savedUsername !== currentUsername ||
|
|
514
|
-
savedPassword !== currentPassword ||
|
|
515
|
-
savedApiName !== currentApiName);
|
|
516
|
-
// Check if user has already entered an access token in the UI (not just saved in storage)
|
|
517
|
-
const userEnteredAccessToken = message.redditAccessToken?.trim();
|
|
518
|
-
if (userEnteredAccessToken && !configChanged) {
|
|
519
|
-
webviewView.webview.postMessage({
|
|
520
|
-
command: 'status',
|
|
521
|
-
status: 'You already have a Reddit access token in the field. Clear the access token field if you want to generate a new one.',
|
|
522
|
-
type: 'error'
|
|
523
|
-
});
|
|
524
|
-
return;
|
|
525
|
-
}
|
|
526
|
-
// Save the Reddit configuration details for persistence
|
|
527
|
-
await this._context.secrets.store('redditClientId', currentClientId);
|
|
528
|
-
await this._context.secrets.store('redditClientSecret', currentClientSecret);
|
|
529
|
-
await this._context.secrets.store('redditUsername', currentUsername);
|
|
530
|
-
await this._context.secrets.store('redditPassword', currentPassword);
|
|
531
|
-
// Store in globalState for config name (non-sensitive data)
|
|
532
|
-
this._context.globalState.update('redditApiName', currentApiName);
|
|
533
|
-
// Import the existing function and use proper parameters
|
|
534
|
-
const { generateRedditTokens } = await Promise.resolve().then(() => __importStar(require('./reddit')));
|
|
535
|
-
const tokenData = await generateRedditTokens(currentClientId, currentClientSecret, currentUsername, currentPassword);
|
|
536
|
-
// Store the generated tokens (only store refresh token if it exists)
|
|
537
|
-
await this._context.secrets.store('redditAccessToken', tokenData.access_token || '');
|
|
538
|
-
if (tokenData.refresh_token) {
|
|
539
|
-
await this._context.secrets.store('redditRefreshToken', tokenData.refresh_token);
|
|
540
|
-
}
|
|
541
|
-
else {
|
|
542
|
-
// For script apps, remove any stored refresh token
|
|
543
|
-
await this._context.secrets.delete('redditRefreshToken');
|
|
544
|
-
}
|
|
545
|
-
// Send success message with indication if this was a regeneration
|
|
546
|
-
const successMessage = configChanged && savedAccessToken
|
|
547
|
-
? 'Reddit tokens regenerated successfully! Old token replaced.'
|
|
548
|
-
: 'Reddit tokens generated successfully!';
|
|
549
|
-
webviewView.webview.postMessage({
|
|
550
|
-
command: 'redditTokensGenerated',
|
|
551
|
-
tokens: {
|
|
552
|
-
accessToken: tokenData.access_token,
|
|
553
|
-
refreshToken: tokenData.refresh_token
|
|
554
|
-
}
|
|
555
|
-
});
|
|
556
|
-
webviewView.webview.postMessage({
|
|
557
|
-
command: 'status',
|
|
558
|
-
status: successMessage,
|
|
559
|
-
type: 'success'
|
|
560
|
-
});
|
|
561
|
-
}
|
|
562
|
-
catch (error) {
|
|
563
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
564
|
-
// Provide more helpful error message for authentication issues
|
|
565
|
-
let userMessage = errorMessage;
|
|
566
|
-
if (errorMessage.includes('401')) {
|
|
567
|
-
userMessage = 'Invalid Reddit credentials. Please check your Client ID, Secret, Username, and Password.';
|
|
568
|
-
}
|
|
569
|
-
else if (errorMessage.includes('unsupported_grant_type')) {
|
|
570
|
-
userMessage = 'Reddit password authentication is not supported. Please use Reddit app with "script" OAuth type.';
|
|
571
|
-
}
|
|
572
|
-
else if (errorMessage.includes('invalid_client')) {
|
|
573
|
-
userMessage = 'Invalid Reddit Client ID or Secret. Please check your app credentials.';
|
|
574
|
-
}
|
|
575
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error generating Reddit tokens: ${userMessage}`, type: 'error' });
|
|
576
|
-
}
|
|
577
|
-
return;
|
|
578
|
-
}
|
|
579
|
-
case 'getRedditFlairs': {
|
|
580
|
-
try {
|
|
581
|
-
const { getRedditFlairs } = await Promise.resolve().then(() => __importStar(require('./reddit')));
|
|
582
|
-
const accessToken = await this._context.secrets.get('redditAccessToken') || '';
|
|
583
|
-
if (!accessToken) {
|
|
584
|
-
webviewView.webview.postMessage({ command: 'status', status: 'Reddit access token required.', type: 'error' });
|
|
585
|
-
return;
|
|
586
|
-
}
|
|
587
|
-
const flairs = await getRedditFlairs(accessToken, message.subreddit);
|
|
588
|
-
webviewView.webview.postMessage({
|
|
589
|
-
command: 'redditFlairsLoaded',
|
|
590
|
-
subreddit: message.subreddit,
|
|
591
|
-
flairs: flairs
|
|
592
|
-
});
|
|
593
|
-
}
|
|
594
|
-
catch (error) {
|
|
595
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
596
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error loading Reddit flairs: ${errorMessage}`, type: 'error' });
|
|
597
|
-
}
|
|
598
|
-
return;
|
|
599
|
-
}
|
|
600
|
-
case 'getRedditUserPosts': {
|
|
601
|
-
try {
|
|
602
|
-
const { getRedditUserPosts } = await Promise.resolve().then(() => __importStar(require('./reddit')));
|
|
603
|
-
const accessToken = await this._context.secrets.get('redditAccessToken') || '';
|
|
604
|
-
if (!accessToken) {
|
|
605
|
-
webviewView.webview.postMessage({ command: 'status', status: 'Reddit access token required.', type: 'error' });
|
|
606
|
-
return;
|
|
607
|
-
}
|
|
608
|
-
const posts = await getRedditUserPosts(accessToken, message.username, message.limit);
|
|
609
|
-
webviewView.webview.postMessage({
|
|
610
|
-
command: 'redditUserPostsRetrieved',
|
|
611
|
-
posts: posts
|
|
612
|
-
});
|
|
613
|
-
}
|
|
614
|
-
catch (error) {
|
|
615
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
616
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error loading Reddit posts: ${errorMessage}`, type: 'error' });
|
|
617
|
-
}
|
|
618
|
-
return;
|
|
619
|
-
}
|
|
620
|
-
case 'editRedditPost': {
|
|
621
|
-
try {
|
|
622
|
-
const { editRedditPost } = await Promise.resolve().then(() => __importStar(require('./reddit')));
|
|
623
|
-
const accessToken = await this._context.secrets.get('redditAccessToken') || '';
|
|
624
|
-
if (!accessToken) {
|
|
625
|
-
webviewView.webview.postMessage({ command: 'status', status: 'Reddit credentials required.', type: 'error' });
|
|
626
|
-
return;
|
|
627
|
-
}
|
|
628
|
-
const success = await editRedditPost(accessToken, message.postId, message.newText);
|
|
629
|
-
if (success) {
|
|
630
|
-
webviewView.webview.postMessage({ command: 'status', status: 'Reddit post updated successfully!', type: 'success' });
|
|
631
|
-
}
|
|
632
|
-
else {
|
|
633
|
-
webviewView.webview.postMessage({ command: 'status', status: 'Failed to update Reddit post.', type: 'error' });
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
catch (error) {
|
|
637
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
638
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error updating Reddit post: ${errorMessage}`, type: 'error' });
|
|
639
|
-
}
|
|
640
|
-
return;
|
|
641
|
-
}
|
|
642
|
-
case 'deleteRedditPost': {
|
|
643
|
-
try {
|
|
644
|
-
const { deleteRedditPost } = await Promise.resolve().then(() => __importStar(require('./reddit')));
|
|
645
|
-
const accessToken = await this._context.secrets.get('redditAccessToken') || '';
|
|
646
|
-
if (!accessToken) {
|
|
647
|
-
webviewView.webview.postMessage({ command: 'status', status: 'Reddit credentials required.', type: 'error' });
|
|
648
|
-
return;
|
|
649
|
-
}
|
|
650
|
-
const success = await deleteRedditPost(accessToken, message.postId);
|
|
651
|
-
if (success) {
|
|
652
|
-
webviewView.webview.postMessage({ command: 'status', status: 'Reddit post deleted successfully!', type: 'success' });
|
|
653
|
-
}
|
|
654
|
-
else {
|
|
655
|
-
webviewView.webview.postMessage({ command: 'status', status: 'Failed to delete Reddit post.', type: 'error' });
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
catch (error) {
|
|
659
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
660
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error deleting Reddit post: ${errorMessage}`, type: 'error' });
|
|
661
|
-
}
|
|
662
|
-
return;
|
|
663
|
-
}
|
|
664
|
-
case 'loadSavedApis': {
|
|
665
|
-
try {
|
|
666
|
-
const storageManager = new (await Promise.resolve().then(() => __importStar(require('./storage-manager')))).StorageManager(this._context);
|
|
667
|
-
const savedApis = storageManager.loadSavedApis(message.platform);
|
|
668
|
-
webviewView.webview.postMessage({
|
|
669
|
-
command: 'savedApisLoaded',
|
|
670
|
-
savedApis: savedApis
|
|
671
|
-
});
|
|
672
|
-
}
|
|
673
|
-
catch (error) {
|
|
674
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error loading saved APIs: ${error}`, type: 'error' });
|
|
675
|
-
}
|
|
676
|
-
return;
|
|
677
|
-
}
|
|
678
|
-
case 'saveApiConfiguration': {
|
|
679
|
-
try {
|
|
680
|
-
const { StorageManager } = await Promise.resolve().then(() => __importStar(require('./storage-manager')));
|
|
681
|
-
const storageManager = new StorageManager(this._context);
|
|
682
|
-
storageManager.saveApiConfiguration(message.apiConfig);
|
|
683
|
-
webviewView.webview.postMessage({ command: 'status', status: 'API configuration saved!', type: 'success' });
|
|
684
|
-
webviewView.webview.postMessage({ command: 'apiConfigurationSaved' });
|
|
685
|
-
}
|
|
686
|
-
catch (error) {
|
|
687
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error saving API configuration: ${error}`, type: 'error' });
|
|
688
|
-
}
|
|
689
|
-
return;
|
|
690
|
-
}
|
|
691
|
-
case 'deleteApiConfiguration': {
|
|
692
|
-
try {
|
|
693
|
-
const { StorageManager } = await Promise.resolve().then(() => __importStar(require('./storage-manager')));
|
|
694
|
-
const storageManager = new StorageManager(this._context);
|
|
695
|
-
storageManager.deleteApiConfiguration(message.apiId);
|
|
696
|
-
webviewView.webview.postMessage({ command: 'status', status: 'API configuration deleted!', type: 'success' });
|
|
697
|
-
}
|
|
698
|
-
catch (error) {
|
|
699
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error deleting API configuration: ${error}`, type: 'error' });
|
|
700
|
-
}
|
|
701
|
-
return;
|
|
702
|
-
}
|
|
703
|
-
case 'share': {
|
|
704
|
-
{
|
|
705
|
-
try {
|
|
706
|
-
const { platforms, post, mediaFilePaths } = message;
|
|
707
|
-
if (!platforms || platforms.length === 0) {
|
|
708
|
-
webviewView.webview.postMessage({ command: 'status', status: 'No platforms selected', type: 'error' });
|
|
709
|
-
return;
|
|
710
|
-
}
|
|
711
|
-
if (!post || !post.trim()) {
|
|
712
|
-
webviewView.webview.postMessage({ command: 'status', status: 'Post content is required', type: 'error' });
|
|
713
|
-
return;
|
|
714
|
-
}
|
|
715
|
-
const postData = {
|
|
716
|
-
text: post.trim(),
|
|
717
|
-
media: mediaFilePaths || []
|
|
718
|
-
};
|
|
719
|
-
// Get post ID from history for analytics
|
|
720
|
-
const history = this._context.globalState.get('postHistory', []);
|
|
721
|
-
const mostRecentPost = history[0];
|
|
722
|
-
const postId = mostRecentPost?.id;
|
|
723
|
-
// Start unified sharing
|
|
724
|
-
webviewView.webview.postMessage({
|
|
725
|
-
command: 'status',
|
|
726
|
-
status: `Sharing to ${platforms.length} platform(s)...`,
|
|
727
|
-
type: 'info'
|
|
728
|
-
});
|
|
729
|
-
await this.unifiedSharePost(webviewView, platforms, postData, mediaFilePaths, postId);
|
|
730
|
-
}
|
|
731
|
-
catch (error) {
|
|
732
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
733
|
-
webviewView.webview.postMessage({
|
|
734
|
-
command: 'status',
|
|
735
|
-
status: `Error during unified sharing: ${errorMessage}`,
|
|
736
|
-
type: 'error'
|
|
737
|
-
});
|
|
738
|
-
}
|
|
739
|
-
return;
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
case 'setDefaultApiConfiguration': {
|
|
743
|
-
try {
|
|
744
|
-
const { StorageManager } = await Promise.resolve().then(() => __importStar(require('./storage-manager')));
|
|
745
|
-
const storageManager = new StorageManager(this._context);
|
|
746
|
-
storageManager.setDefaultApiConfiguration(message.platform, message.apiId);
|
|
747
|
-
webviewView.webview.postMessage({ command: 'status', status: `${message.platform.charAt(0).toUpperCase() + message.platform.slice(1)} default configuration updated!`, type: 'success' });
|
|
748
|
-
webviewView.webview.postMessage({ command: 'defaultConfigurationSet' });
|
|
749
|
-
}
|
|
750
|
-
catch (error) {
|
|
751
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error setting default configuration: ${error}`, type: 'error' });
|
|
752
|
-
}
|
|
753
|
-
return;
|
|
754
|
-
}
|
|
755
|
-
case 'loadApiConfiguration': {
|
|
756
|
-
try {
|
|
757
|
-
const { StorageManager } = await Promise.resolve().then(() => __importStar(require('./storage-manager')));
|
|
758
|
-
const storageManager = new StorageManager(this._context);
|
|
759
|
-
const apiConfig = storageManager.loadApiConfiguration(message.apiId);
|
|
760
|
-
if (apiConfig) {
|
|
761
|
-
webviewView.webview.postMessage({
|
|
762
|
-
command: 'apiConfigurationLoaded',
|
|
763
|
-
apiConfig: apiConfig
|
|
764
|
-
});
|
|
765
|
-
}
|
|
766
|
-
else {
|
|
767
|
-
webviewView.webview.postMessage({ command: 'status', status: 'API configuration not found', type: 'error' });
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
catch (error) {
|
|
771
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error loading API configuration: ${error}`, type: 'error' });
|
|
772
|
-
}
|
|
773
|
-
return;
|
|
774
|
-
}
|
|
775
|
-
case 'loadPostHistory':
|
|
776
|
-
await this._loadPostHistory(webviewView);
|
|
777
|
-
return;
|
|
778
|
-
case 'loadAnalytics': {
|
|
779
|
-
const analytics = this._calculateAnalytics();
|
|
780
|
-
webviewView.webview.postMessage({
|
|
781
|
-
command: 'updateAnalytics',
|
|
782
|
-
analytics: analytics
|
|
783
|
-
});
|
|
784
|
-
return;
|
|
785
|
-
}
|
|
786
|
-
case 'selectMediaFiles': {
|
|
787
|
-
try {
|
|
788
|
-
// Use VS Code's file picker to select files from anywhere on the system
|
|
789
|
-
const fileUris = await vscode.window.showOpenDialog({
|
|
790
|
-
canSelectFiles: true,
|
|
791
|
-
canSelectFolders: false,
|
|
792
|
-
canSelectMany: true,
|
|
793
|
-
filters: {
|
|
794
|
-
'Images': ['jpg', 'jpeg', 'png', 'gif'],
|
|
795
|
-
'Videos': ['mp4'],
|
|
796
|
-
'All supported': ['jpg', 'jpeg', 'png', 'gif', 'mp4']
|
|
797
|
-
},
|
|
798
|
-
openLabel: 'Select Media Files from Anywhere'
|
|
799
|
-
});
|
|
800
|
-
if (fileUris && fileUris.length > 0) {
|
|
801
|
-
// Get file stats for size info
|
|
802
|
-
const mediaFiles = [];
|
|
803
|
-
for (const uri of fileUris) {
|
|
804
|
-
try {
|
|
805
|
-
const stats = await vscode.workspace.fs.stat(uri);
|
|
806
|
-
const fileName = path.basename(uri.fsPath);
|
|
807
|
-
const fileSize = stats.size;
|
|
808
|
-
mediaFiles.push({
|
|
809
|
-
mediaPath: uri.fsPath,
|
|
810
|
-
mediaFilePath: uri.fsPath,
|
|
811
|
-
fileName: fileName,
|
|
812
|
-
fileSize: fileSize
|
|
813
|
-
});
|
|
814
|
-
}
|
|
815
|
-
catch (error) {
|
|
816
|
-
console.warn(`Could not get stats for ${uri.fsPath}:`, error);
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
if (mediaFiles.length > 0) {
|
|
820
|
-
// Send the selected files back to webview
|
|
821
|
-
webviewView.webview.postMessage({
|
|
822
|
-
command: 'mediaSelected',
|
|
823
|
-
mediaFiles: mediaFiles
|
|
824
|
-
});
|
|
825
|
-
webviewView.webview.postMessage({
|
|
826
|
-
command: 'status',
|
|
827
|
-
status: `${mediaFiles.length} file(s) selected successfully!`,
|
|
828
|
-
type: 'success'
|
|
829
|
-
});
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
catch (error) {
|
|
834
|
-
webviewView.webview.postMessage({
|
|
835
|
-
command: 'status',
|
|
836
|
-
status: `Error selecting files: ${error}`,
|
|
837
|
-
type: 'error'
|
|
838
|
-
});
|
|
839
|
-
}
|
|
840
|
-
return;
|
|
841
|
-
}
|
|
842
|
-
case 'uploadFile': {
|
|
843
|
-
try {
|
|
844
|
-
// Handle file upload from webview (drag & drop, click to browse)
|
|
845
|
-
const { file } = message;
|
|
846
|
-
if (!file || !file.name || !file.base64Data) {
|
|
847
|
-
webviewView.webview.postMessage({
|
|
848
|
-
command: 'status',
|
|
849
|
-
status: 'Invalid file data provided.',
|
|
850
|
-
type: 'error'
|
|
851
|
-
});
|
|
852
|
-
return;
|
|
853
|
-
}
|
|
854
|
-
// Get extension storage directory for media files
|
|
855
|
-
const storageUri = this._context.globalStorageUri || vscode.Uri.file(path.join(os.tmpdir(), 'dotshare-media'));
|
|
856
|
-
const mediaDir = vscode.Uri.joinPath(storageUri, 'media');
|
|
857
|
-
// Create media directory if it doesn't exist
|
|
858
|
-
try {
|
|
859
|
-
await vscode.workspace.fs.createDirectory(mediaDir);
|
|
860
|
-
}
|
|
861
|
-
catch (error) {
|
|
862
|
-
console.warn('Could not create media directory:', error);
|
|
863
|
-
}
|
|
864
|
-
// Convert base64 data back to binary
|
|
865
|
-
const binaryString = atob(file.base64Data);
|
|
866
|
-
const bytes = new Uint8Array(binaryString.length);
|
|
867
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
868
|
-
bytes[i] = binaryString.charCodeAt(i);
|
|
869
|
-
}
|
|
870
|
-
// Create unique filename with timestamp
|
|
871
|
-
const fileName = `${Date.now()}-${file.name}`;
|
|
872
|
-
const fileUri = vscode.Uri.joinPath(mediaDir, fileName);
|
|
873
|
-
// Write the file to disk
|
|
874
|
-
await vscode.workspace.fs.writeFile(fileUri, bytes);
|
|
875
|
-
// Send success message back to webview with the saved file path
|
|
876
|
-
webviewView.webview.postMessage({
|
|
877
|
-
command: 'fileUploaded',
|
|
878
|
-
mediaPath: fileUri.fsPath,
|
|
879
|
-
mediaFilePath: fileUri.fsPath,
|
|
880
|
-
fileName: file.name,
|
|
881
|
-
fileSize: file.size
|
|
882
|
-
});
|
|
883
|
-
webviewView.webview.postMessage({
|
|
884
|
-
command: 'status',
|
|
885
|
-
status: `File "${file.name}" uploaded successfully!`,
|
|
886
|
-
type: 'success'
|
|
887
|
-
});
|
|
888
|
-
}
|
|
889
|
-
catch (error) {
|
|
890
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
891
|
-
webviewView.webview.postMessage({
|
|
892
|
-
command: 'status',
|
|
893
|
-
status: `Error uploading file: ${errorMessage}`,
|
|
894
|
-
type: 'error'
|
|
895
|
-
});
|
|
896
|
-
}
|
|
897
|
-
return;
|
|
898
|
-
}
|
|
899
|
-
case 'attachMedia': {
|
|
900
|
-
try {
|
|
901
|
-
// Handle media attachment from either uploadFile result or selectMediaFiles
|
|
902
|
-
const { mediaFilePath, mediaFilePaths, mediaPath, fileName, fileSize } = message;
|
|
903
|
-
// Handle multiple files (from selectMediaFiles)
|
|
904
|
-
if (mediaFilePaths && Array.isArray(mediaFilePaths)) {
|
|
905
|
-
const mediaFiles = mediaFilePaths.map(path => ({
|
|
906
|
-
mediaPath: path,
|
|
907
|
-
mediaFilePath: path,
|
|
908
|
-
fileName: fileName || path.split(/[/\\]/).pop() || 'unknown',
|
|
909
|
-
fileSize: fileSize || 0
|
|
910
|
-
}));
|
|
911
|
-
webviewView.webview.postMessage({
|
|
912
|
-
command: 'mediaAttached',
|
|
913
|
-
mediaFiles: mediaFiles
|
|
914
|
-
});
|
|
915
|
-
webviewView.webview.postMessage({
|
|
916
|
-
command: 'status',
|
|
917
|
-
status: `${mediaFilePaths.length} file(s) attached successfully!`,
|
|
918
|
-
type: 'success'
|
|
919
|
-
});
|
|
920
|
-
}
|
|
921
|
-
// Handle single file (from uploadFile or direct attach)
|
|
922
|
-
else if (mediaFilePath || mediaPath) {
|
|
923
|
-
const filePath = mediaFilePath || mediaPath || '';
|
|
924
|
-
const mediaFiles = [{
|
|
925
|
-
mediaPath: mediaPath || filePath,
|
|
926
|
-
mediaFilePath: filePath,
|
|
927
|
-
fileName: fileName || filePath.split(/[/\\]/).pop() || 'unknown',
|
|
928
|
-
fileSize: fileSize || 0
|
|
929
|
-
}];
|
|
930
|
-
webviewView.webview.postMessage({
|
|
931
|
-
command: 'mediaAttached',
|
|
932
|
-
mediaFiles: mediaFiles
|
|
933
|
-
});
|
|
934
|
-
webviewView.webview.postMessage({
|
|
935
|
-
command: 'status',
|
|
936
|
-
status: `File attached successfully!`,
|
|
937
|
-
type: 'success'
|
|
938
|
-
});
|
|
939
|
-
}
|
|
940
|
-
else {
|
|
941
|
-
webviewView.webview.postMessage({
|
|
942
|
-
command: 'status',
|
|
943
|
-
status: 'No media files provided for attachment.',
|
|
944
|
-
type: 'error'
|
|
945
|
-
});
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
catch (error) {
|
|
949
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
950
|
-
webviewView.webview.postMessage({
|
|
951
|
-
command: 'status',
|
|
952
|
-
status: `Error attaching media: ${errorMessage}`,
|
|
953
|
-
type: 'error'
|
|
954
|
-
});
|
|
955
|
-
}
|
|
956
|
-
return;
|
|
957
|
-
}
|
|
958
|
-
case 'removeMedia': {
|
|
959
|
-
try {
|
|
960
|
-
// Handle media removal
|
|
961
|
-
webviewView.webview.postMessage({
|
|
962
|
-
command: 'mediaRemoved'
|
|
963
|
-
});
|
|
964
|
-
webviewView.webview.postMessage({
|
|
965
|
-
command: 'status',
|
|
966
|
-
status: 'Media attachment removed.',
|
|
967
|
-
type: 'success'
|
|
968
|
-
});
|
|
969
|
-
}
|
|
970
|
-
catch (error) {
|
|
971
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
972
|
-
webviewView.webview.postMessage({
|
|
973
|
-
command: 'status',
|
|
974
|
-
status: `Error removing media: ${errorMessage}`,
|
|
975
|
-
type: 'error'
|
|
976
|
-
});
|
|
977
|
-
}
|
|
978
|
-
return;
|
|
979
|
-
}
|
|
980
|
-
default:
|
|
981
|
-
console.log('Unhandled message:', message.command);
|
|
982
|
-
return;
|
|
983
|
-
}
|
|
984
|
-
}, undefined, this._context.subscriptions);
|
|
985
|
-
}
|
|
986
|
-
_generatePostId() {
|
|
987
|
-
return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
988
|
-
}
|
|
989
|
-
_savePostToHistory(aiProvider, aiModel, postData) {
|
|
990
|
-
const history = this._context.globalState.get('postHistory', []);
|
|
991
|
-
const historicalPost = {
|
|
992
|
-
id: this._generatePostId(),
|
|
993
|
-
timestamp: new Date().toISOString(),
|
|
994
|
-
aiProvider,
|
|
995
|
-
aiModel,
|
|
996
|
-
postData,
|
|
997
|
-
shares: []
|
|
998
|
-
};
|
|
999
|
-
// Keep only last 50 posts to prevent storage bloat
|
|
1000
|
-
history.unshift(historicalPost);
|
|
1001
|
-
if (history.length > 50) {
|
|
1002
|
-
history.splice(50);
|
|
1003
|
-
}
|
|
1004
|
-
this._context.globalState.update('postHistory', history);
|
|
1005
|
-
// Update lastPost for backward compatibility
|
|
1006
|
-
this._context.globalState.update('lastPost', postData);
|
|
1007
|
-
}
|
|
1008
|
-
_recordShare(postId, platform, success, errorMessage, postIdOnPlatform) {
|
|
1009
|
-
const history = this._context.globalState.get('postHistory', []);
|
|
1010
|
-
const postIndex = history.findIndex(post => post.id === postId);
|
|
1011
|
-
if (postIndex !== -1) {
|
|
1012
|
-
const shareRecord = {
|
|
1013
|
-
platform,
|
|
1014
|
-
timestamp: new Date().toISOString(),
|
|
1015
|
-
success,
|
|
1016
|
-
errorMessage,
|
|
1017
|
-
postId: postIdOnPlatform
|
|
1018
|
-
};
|
|
1019
|
-
history[postIndex].shares.push(shareRecord);
|
|
1020
|
-
this._context.globalState.update('postHistory', history);
|
|
1021
|
-
}
|
|
1022
|
-
}
|
|
1023
|
-
async _loadFromSecretsOrDefault(secretKey) {
|
|
1024
|
-
const storageManager = new (await Promise.resolve().then(() => __importStar(require('./storage-manager')))).StorageManager(this._context);
|
|
1025
|
-
return await storageManager.loadFromSecretsOrDefault(secretKey);
|
|
1026
|
-
}
|
|
1027
|
-
async _loadConfiguration(webviewView) {
|
|
1028
|
-
try {
|
|
1029
|
-
const storageManager = new (await Promise.resolve().then(() => __importStar(require('./storage-manager')))).StorageManager(this._context);
|
|
1030
|
-
const config = await storageManager.loadConfiguration();
|
|
1031
|
-
webviewView.webview.postMessage({
|
|
1032
|
-
command: 'updateConfiguration',
|
|
1033
|
-
selectedModel: config.selectedModel ? { ...config.selectedModel, apiKey: config.apiKey } : config.selectedModel,
|
|
1034
|
-
linkedinToken: config.linkedinToken,
|
|
1035
|
-
telegramBot: config.telegramBot,
|
|
1036
|
-
telegramChat: config.telegramChat,
|
|
1037
|
-
xAccessToken: config.xAccessToken,
|
|
1038
|
-
xAccessSecret: config.xAccessSecret,
|
|
1039
|
-
facebookToken: config.facebookToken,
|
|
1040
|
-
facebookPageToken: config.facebookPageToken,
|
|
1041
|
-
facebookPageId: config.facebookPageId,
|
|
1042
|
-
discordWebhookUrl: config.discordWebhookUrl,
|
|
1043
|
-
redditAccessToken: config.redditAccessToken,
|
|
1044
|
-
redditRefreshToken: config.redditRefreshToken,
|
|
1045
|
-
redditClientId: config.redditClientId,
|
|
1046
|
-
redditClientSecret: config.redditClientSecret,
|
|
1047
|
-
redditUsername: config.redditUsername,
|
|
1048
|
-
redditPassword: config.redditPassword,
|
|
1049
|
-
redditApiName: config.redditApiName,
|
|
1050
|
-
blueskyIdentifier: config.blueskyIdentifier,
|
|
1051
|
-
blueskyPassword: config.blueskyPassword
|
|
1052
|
-
});
|
|
1053
|
-
}
|
|
1054
|
-
catch (error) {
|
|
1055
|
-
console.error('Error loading configuration:', error);
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
async _loadScheduledPosts(webviewView) {
|
|
1059
|
-
try {
|
|
1060
|
-
const scheduledPosts = this._scheduledPostsStorage.loadScheduledPosts();
|
|
1061
|
-
// Start the scheduler if there are scheduled posts and it's not already running
|
|
1062
|
-
if (scheduledPosts.length > 0 && !this._scheduler) {
|
|
1063
|
-
const storagePath = this._context.globalStorageUri?.fsPath || this._context.extensionPath;
|
|
1064
|
-
const credentialsGetter = async () => ({
|
|
1065
|
-
linkedinToken: await this._context.secrets.get('linkedinToken') || '',
|
|
1066
|
-
telegramBot: await this._context.secrets.get('telegramBot') || '',
|
|
1067
|
-
telegramChat: await this._context.secrets.get('telegramChat') || ''
|
|
1068
|
-
});
|
|
1069
|
-
this._scheduler = new scheduler_1.Scheduler(storagePath, undefined, credentialsGetter);
|
|
1070
|
-
this._scheduler.start();
|
|
1071
|
-
console.log('Scheduler started for existing scheduled posts');
|
|
1072
|
-
}
|
|
1073
|
-
webviewView.webview.postMessage({
|
|
1074
|
-
command: 'updateScheduledPosts',
|
|
1075
|
-
scheduledPosts: scheduledPosts
|
|
1076
|
-
});
|
|
1077
|
-
}
|
|
1078
|
-
catch (error) {
|
|
1079
|
-
console.error('Error loading scheduled posts:', error);
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
async _loadPostHistory(webviewView) {
|
|
1083
|
-
try {
|
|
1084
|
-
const postHistory = this._context.globalState.get('postHistory', []);
|
|
1085
|
-
const analytics = this._calculateAnalytics();
|
|
1086
|
-
webviewView.webview.postMessage({
|
|
1087
|
-
command: 'updatePostHistory',
|
|
1088
|
-
postHistory: postHistory
|
|
1089
|
-
});
|
|
1090
|
-
webviewView.webview.postMessage({
|
|
1091
|
-
command: 'updateAnalytics',
|
|
1092
|
-
analytics: analytics
|
|
1093
|
-
});
|
|
1094
|
-
}
|
|
1095
|
-
catch (error) {
|
|
1096
|
-
console.error('Error loading post history:', error);
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
_calculateAnalytics() {
|
|
1100
|
-
const history = this._context.globalState.get('postHistory', []);
|
|
1101
|
-
const totalPosts = history.length;
|
|
1102
|
-
let successfulShares = 0;
|
|
1103
|
-
let failedShares = 0;
|
|
1104
|
-
let linkedinShares = 0;
|
|
1105
|
-
let telegramShares = 0;
|
|
1106
|
-
let xShares = 0;
|
|
1107
|
-
let facebookShares = 0;
|
|
1108
|
-
let discordShares = 0;
|
|
1109
|
-
let redditShares = 0;
|
|
1110
|
-
let blueskyShares = 0;
|
|
1111
|
-
for (const post of history) {
|
|
1112
|
-
for (const share of post.shares) {
|
|
1113
|
-
switch (share.platform) {
|
|
1114
|
-
case 'linkedin':
|
|
1115
|
-
linkedinShares++;
|
|
1116
|
-
break;
|
|
1117
|
-
case 'telegram':
|
|
1118
|
-
telegramShares++;
|
|
1119
|
-
break;
|
|
1120
|
-
case 'x':
|
|
1121
|
-
xShares++;
|
|
1122
|
-
break;
|
|
1123
|
-
case 'facebook':
|
|
1124
|
-
facebookShares++;
|
|
1125
|
-
break;
|
|
1126
|
-
case 'discord':
|
|
1127
|
-
discordShares++;
|
|
1128
|
-
break;
|
|
1129
|
-
case 'reddit':
|
|
1130
|
-
redditShares++;
|
|
1131
|
-
break;
|
|
1132
|
-
case 'bluesky':
|
|
1133
|
-
blueskyShares++;
|
|
1134
|
-
break;
|
|
1135
|
-
}
|
|
1136
|
-
if (share.success) {
|
|
1137
|
-
successfulShares++;
|
|
1138
|
-
}
|
|
1139
|
-
else {
|
|
1140
|
-
failedShares++;
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
const totalShares = successfulShares + failedShares;
|
|
1145
|
-
const successRate = totalShares > 0 ? Math.round((successfulShares / totalShares) * 100) : 0;
|
|
1146
|
-
return {
|
|
1147
|
-
totalPosts,
|
|
1148
|
-
successfulShares,
|
|
1149
|
-
failedShares,
|
|
1150
|
-
linkedinShares,
|
|
1151
|
-
telegramShares,
|
|
1152
|
-
xShares,
|
|
1153
|
-
facebookShares,
|
|
1154
|
-
discordShares,
|
|
1155
|
-
redditShares,
|
|
1156
|
-
blueskyShares,
|
|
1157
|
-
successRate
|
|
1158
|
-
};
|
|
1159
|
-
}
|
|
1160
|
-
async shareToFacebookWithUpdate(webviewView, post, message, postId) {
|
|
1161
|
-
void webviewView, void post, void message, void postId;
|
|
1162
|
-
throw new Error('Facebook sharing not yet implemented');
|
|
1163
|
-
}
|
|
1164
|
-
async shareToDiscordWithUpdate(webviewView, post, message, postId) {
|
|
1165
|
-
void webviewView, void post, void message, void postId;
|
|
1166
|
-
throw new Error('Discord sharing not yet implemented');
|
|
1167
|
-
}
|
|
1168
|
-
async shareToXWithUpdate(webviewView, post, message, postId) {
|
|
1169
|
-
void webviewView, void post, void message, void postId;
|
|
1170
|
-
throw new Error('X/Twitter sharing not yet implemented');
|
|
1171
|
-
}
|
|
1172
|
-
async shareToRedditWithUpdate(webviewView, post, message, postId) {
|
|
1173
|
-
try {
|
|
1174
|
-
const msg = message;
|
|
1175
|
-
const { shareToReddit } = await Promise.resolve().then(() => __importStar(require('./reddit')));
|
|
1176
|
-
const credentials = {
|
|
1177
|
-
accessToken: msg.redditAccessToken || '',
|
|
1178
|
-
refreshToken: msg.redditRefreshToken || undefined // Allow undefined for script apps
|
|
1179
|
-
};
|
|
1180
|
-
// Create Reddit post data from message
|
|
1181
|
-
const redditPostData = {
|
|
1182
|
-
text: msg.post || '',
|
|
1183
|
-
media: post.media,
|
|
1184
|
-
subreddit: msg.redditSubreddit?.startsWith('r/') ? msg.redditSubreddit.substring(2) : msg.redditSubreddit || '',
|
|
1185
|
-
title: msg.redditTitle || '',
|
|
1186
|
-
flairId: msg.redditFlairId,
|
|
1187
|
-
isSelfPost: msg.redditPostType !== 'link',
|
|
1188
|
-
spoiler: msg.redditSpoiler
|
|
1189
|
-
};
|
|
1190
|
-
const postIdOnPlatform = await shareToReddit(credentials.accessToken, credentials.refreshToken, redditPostData);
|
|
1191
|
-
// Record the share
|
|
1192
|
-
if (postId) {
|
|
1193
|
-
this._recordShare(postId, 'reddit', true, undefined, postIdOnPlatform);
|
|
1194
|
-
}
|
|
1195
|
-
webviewView.webview.postMessage({ command: 'status', status: 'Successfully posted to Reddit!', type: 'success' });
|
|
1196
|
-
return postIdOnPlatform;
|
|
1197
|
-
}
|
|
1198
|
-
catch (error) {
|
|
1199
|
-
console.error('Error sharing to Reddit:', error);
|
|
1200
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1201
|
-
if (postId) {
|
|
1202
|
-
this._recordShare(postId, 'reddit', false, errorMessage);
|
|
1203
|
-
}
|
|
1204
|
-
throw new Error(`Reddit sharing failed: ${errorMessage}`);
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
async shareToLinkedInWithUpdate(webviewView, post, message, postId) {
|
|
1208
|
-
try {
|
|
1209
|
-
const msg = message;
|
|
1210
|
-
const { shareToLinkedIn } = await Promise.resolve().then(() => __importStar(require('./linkedin')));
|
|
1211
|
-
await shareToLinkedIn(post, msg.linkedinToken || await this._context.secrets.get('linkedinToken') || '', {
|
|
1212
|
-
onSuccess: (message) => {
|
|
1213
|
-
webviewView.webview.postMessage({ command: 'status', status: message, type: 'success' });
|
|
1214
|
-
if (postId) {
|
|
1215
|
-
this._recordShare(postId, 'linkedin', true);
|
|
1216
|
-
}
|
|
1217
|
-
},
|
|
1218
|
-
onError: (message) => {
|
|
1219
|
-
webviewView.webview.postMessage({ command: 'status', status: message, type: 'error' });
|
|
1220
|
-
if (postId) {
|
|
1221
|
-
this._recordShare(postId, 'linkedin', false, message);
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
});
|
|
1225
|
-
}
|
|
1226
|
-
catch (error) {
|
|
1227
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1228
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error sharing to LinkedIn: ${errorMessage}`, type: 'error' });
|
|
1229
|
-
if (postId) {
|
|
1230
|
-
this._recordShare(postId, 'linkedin', false, errorMessage);
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
async shareToTelegramWithUpdate(webviewView, post, message, postId) {
|
|
1235
|
-
try {
|
|
1236
|
-
const msg = message;
|
|
1237
|
-
const telegramBot = msg.telegramBot || await this._context.secrets.get('telegramBot') || '';
|
|
1238
|
-
const telegramChat = msg.telegramChat || await this._context.secrets.get('telegramChat') || '';
|
|
1239
|
-
console.log('DEBUG: Telegram sharing with bot:', !!telegramBot, 'chat:', !!telegramChat, 'post:', post.text);
|
|
1240
|
-
const { shareToTelegram } = await Promise.resolve().then(() => __importStar(require('./telegram')));
|
|
1241
|
-
await shareToTelegram(post, telegramBot, telegramChat, {
|
|
1242
|
-
onSuccess: (message) => {
|
|
1243
|
-
webviewView.webview.postMessage({ command: 'status', status: message, type: 'success' });
|
|
1244
|
-
if (postId) {
|
|
1245
|
-
this._recordShare(postId, 'telegram', true);
|
|
1246
|
-
}
|
|
1247
|
-
},
|
|
1248
|
-
onError: (message) => {
|
|
1249
|
-
webviewView.webview.postMessage({ command: 'status', status: message, type: 'error' });
|
|
1250
|
-
if (postId) {
|
|
1251
|
-
this._recordShare(postId, 'telegram', false, message);
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
});
|
|
1255
|
-
}
|
|
1256
|
-
catch (error) {
|
|
1257
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1258
|
-
webviewView.webview.postMessage({ command: 'status', status: `Error sharing to Telegram: ${errorMessage}`, type: 'error' });
|
|
1259
|
-
if (postId) {
|
|
1260
|
-
this._recordShare(postId, 'telegram', false, errorMessage);
|
|
1261
|
-
}
|
|
1262
|
-
}
|
|
1263
|
-
}
|
|
1264
|
-
async shareToBlueSkyWithUpdate(webviewView, post, message, postId) {
|
|
1265
|
-
void webviewView, void post, void message, void postId;
|
|
1266
|
-
throw new Error('BlueSky sharing not yet implemented');
|
|
1267
|
-
}
|
|
1268
|
-
async unifiedSharePost(webviewView, platforms, post, mediaFilePaths = [], postId) {
|
|
1269
|
-
const results = {
|
|
1270
|
-
linkedin: false,
|
|
1271
|
-
telegram: false,
|
|
1272
|
-
x: false,
|
|
1273
|
-
facebook: false,
|
|
1274
|
-
discord: false,
|
|
1275
|
-
reddit: false,
|
|
1276
|
-
bluesky: false
|
|
1277
|
-
};
|
|
1278
|
-
let firstError = null;
|
|
1279
|
-
// Share to each selected platform
|
|
1280
|
-
for (const platform of platforms) {
|
|
1281
|
-
try {
|
|
1282
|
-
const platformMessage = { ...post, mediaFilePaths };
|
|
1283
|
-
switch (platform) {
|
|
1284
|
-
case 'linkedin':
|
|
1285
|
-
await this.shareToLinkedInWithUpdate(webviewView, platformMessage, platformMessage, postId);
|
|
1286
|
-
results.linkedin = true;
|
|
1287
|
-
break;
|
|
1288
|
-
case 'telegram':
|
|
1289
|
-
await this.shareToTelegramWithUpdate(webviewView, platformMessage, platformMessage, postId);
|
|
1290
|
-
results.telegram = true;
|
|
1291
|
-
break;
|
|
1292
|
-
case 'x':
|
|
1293
|
-
await this.shareToXWithUpdate(webviewView, platformMessage, platformMessage, postId);
|
|
1294
|
-
results.x = true;
|
|
1295
|
-
break;
|
|
1296
|
-
case 'facebook':
|
|
1297
|
-
await this.shareToFacebookWithUpdate(webviewView, platformMessage, platformMessage, postId);
|
|
1298
|
-
results.facebook = true;
|
|
1299
|
-
break;
|
|
1300
|
-
case 'discord':
|
|
1301
|
-
await this.shareToDiscordWithUpdate(webviewView, platformMessage, platformMessage, postId);
|
|
1302
|
-
results.discord = true;
|
|
1303
|
-
break;
|
|
1304
|
-
case 'reddit': {
|
|
1305
|
-
const redditMessage = {
|
|
1306
|
-
redditAccessToken: await this._context.secrets.get('redditAccessToken') || '',
|
|
1307
|
-
redditRefreshToken: await this._context.secrets.get('redditRefreshToken') || '',
|
|
1308
|
-
subreddit: 'test',
|
|
1309
|
-
title: post.text?.substring(0, 300) || 'Post from DotShare',
|
|
1310
|
-
post: post.text,
|
|
1311
|
-
mediaFilePaths: mediaFilePaths
|
|
1312
|
-
};
|
|
1313
|
-
await this.shareToRedditWithUpdate(webviewView, platformMessage, redditMessage, postId);
|
|
1314
|
-
results.reddit = true;
|
|
1315
|
-
break;
|
|
1316
|
-
}
|
|
1317
|
-
case 'bluesky':
|
|
1318
|
-
await this.shareToBlueSkyWithUpdate(webviewView, platformMessage, platformMessage, postId);
|
|
1319
|
-
results.bluesky = true;
|
|
1320
|
-
break;
|
|
1321
|
-
default:
|
|
1322
|
-
console.warn(`Unknown platform: ${platform}`);
|
|
1323
|
-
}
|
|
1324
|
-
}
|
|
1325
|
-
catch (error) {
|
|
1326
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1327
|
-
console.error(`Error sharing to ${platform}:`, error);
|
|
1328
|
-
if (!firstError) {
|
|
1329
|
-
firstError = `Error sharing to ${platform}: ${errorMessage}`;
|
|
1330
|
-
}
|
|
1331
|
-
// Record failure for this platform
|
|
1332
|
-
if (postId) {
|
|
1333
|
-
const platformKey = platform;
|
|
1334
|
-
if (platformKey in results) {
|
|
1335
|
-
this._recordShare(postId, platform, false, errorMessage);
|
|
1336
|
-
}
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
}
|
|
1340
|
-
// Count successful shares
|
|
1341
|
-
const successfulShares = Object.values(results).filter(success => success).length;
|
|
1342
|
-
if (platforms.length === 0) {
|
|
1343
|
-
webviewView.webview.postMessage({ command: 'status', status: 'No platforms selected', type: 'error' });
|
|
1344
|
-
}
|
|
1345
|
-
else if (successfulShares === platforms.length) {
|
|
1346
|
-
webviewView.webview.postMessage({
|
|
1347
|
-
command: 'status',
|
|
1348
|
-
status: `Successfully shared to all ${platforms.length} platform(s)!`,
|
|
1349
|
-
type: 'success'
|
|
1350
|
-
});
|
|
1351
|
-
}
|
|
1352
|
-
else if (successfulShares > 0) {
|
|
1353
|
-
webviewView.webview.postMessage({
|
|
1354
|
-
command: 'status',
|
|
1355
|
-
status: `Shared to ${successfulShares}/${platforms.length} platform(s). Check for any errors above.`,
|
|
1356
|
-
type: firstError ? 'error' : 'warning'
|
|
1357
|
-
});
|
|
1358
|
-
}
|
|
1359
|
-
else {
|
|
1360
|
-
webviewView.webview.postMessage({
|
|
1361
|
-
command: 'status',
|
|
1362
|
-
status: `Failed to share to any platforms. ${firstError || ''}`,
|
|
1363
|
-
type: 'error'
|
|
1364
|
-
});
|
|
1365
|
-
}
|
|
1366
|
-
}
|
|
1367
|
-
_getHtmlForWebview(webview) {
|
|
1368
|
-
const indexPath = path.join(this._extensionUri.fsPath, 'media', 'index.html');
|
|
1369
|
-
let html = fs.readFileSync(indexPath, 'utf-8');
|
|
1370
|
-
// Replace resource paths with webview URIs
|
|
1371
|
-
const cssUri = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, 'media', 'assets', 'style.css'));
|
|
1372
|
-
const jsUri = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, 'media', 'app.js'));
|
|
1373
|
-
html = html.replace('./assets/style.css', cssUri.toString());
|
|
1374
|
-
html = html.replace('./app.js', jsUri.toString());
|
|
1375
|
-
return html;
|
|
1376
|
-
}
|
|
1377
|
-
}
|
|
1378
|
-
DotShareProvider.viewType = 'dotshareView';
|
|
1379
|
-
function deactivate() {
|
|
1380
|
-
// Cleanup if needed - currently no resources to clean up
|
|
1381
|
-
}
|
|
1382
|
-
exports.deactivate = deactivate;
|
|
1383
|
-
//# sourceMappingURL=extension.js.map
|