Skip to content

Commit

Permalink
Improve sidebar commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ggodlewski committed Oct 29, 2023
1 parent 41ed4a2 commit 81f7dd6
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 19 deletions.
2 changes: 1 addition & 1 deletion apps/ui/src/components/UtilsMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export const UtilsMixin = {

const url = new URL(authPath, 'http://example.com');
url.searchParams.set('popupWindow', 'true');
authPath = url.pathname + '?' + url.search;
authPath = url.pathname + (url.search || '');

let authPopup;
window['authenticated'] = (url) => {
Expand Down
3 changes: 2 additions & 1 deletion apps/ui/src/modals/ToastsContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export default {
},
methods: {
getHref(hash) {
return this.$router.resolve({ path: this.fullDrivePath, hash });
const resolved = this.$router.resolve({ path: this.fullDrivePath, hash });
return resolved?.fullPath || null;
},
links(toast) {
if (toast.links && 'object' === typeof toast.links) {
Expand Down
1 change: 0 additions & 1 deletion apps/ui/src/pages/DrivesView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export default {
methods: {
async fetch() {
const drives = await this.DriveClientService.getDrives();
console.log('drives', drives);
this.drivesShared = drives.filter(d => !!d.exists);
this.drivesNotShared = drives.filter(d => !d.exists);
},
Expand Down
8 changes: 6 additions & 2 deletions apps/ui/src/pages/GDocsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@
<div class="card-header d-flex" v-if="!syncing && selectedFile.path">
Git
<ul class="nav flex-row flex-grow-1 flex-shrink-0 justify-content-end">
<li>
<small v-if="selectedFile.attachments > 0" :title="selectedFile.attachments + ' images'">&nbsp;(<i class="fa-solid fa-paperclip"></i>{{ selectedFile.attachments }})</small>
</li>
<ToolButton
v-if="gitStats.initialized"
class="pl-1 p-0"
Expand Down Expand Up @@ -194,12 +197,12 @@
</ul>
</div>
<GitFooter class="mt-3 mb-3" v-if="!syncing && selectedFile.path">
<div v-if="selectedFile.status">
<div v-if="selectedFile.status || selectedFile.attachments > 0 || true">
<div class="input-groups">
<textarea v-grow class="form-control" placeholder="Commit message" v-model="commitMsg"></textarea>
</div>
</div>
<div v-if="selectedFile.status" class="mb-3">
<div v-if="selectedFile.status || selectedFile.attachments > 0 || true" class="mb-3">
<button v-if="git_remote_url" type="button" class="btn btn-primary" @click="commitSinglePush"><i v-if="active_jobs.length > 0" class="fa-solid fa-rotate fa-spin"></i> Commit &amp; push</button>
<button type="button" class="btn btn-primary" @click="commitSingle">Commit</button>
</div>
Expand Down Expand Up @@ -375,6 +378,7 @@ export default {
mimeType: response.headers.get('wgd-mime-type'),
previewUrl: response.headers.get('wgd-preview-url'),
status: response.headers.get('wgd-git-status'),
attachments: response.headers.get('wgd-git-attachments'),
lastAuthor: response.headers.get('wgd-last-author')
};
Expand Down
26 changes: 16 additions & 10 deletions src/containers/job/JobManagerContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ export class JobManagerContainer extends Container {
type: 'upload:failed',
err: err.message,
links: {
['#drive_logs:' + currentJob.id]: 'View logs'
['#drive_logs:job-' + currentJob.id]: 'View logs'
},
});
}
Expand All @@ -372,7 +372,7 @@ export class JobManagerContainer extends Container {
type: 'git_reset:failed',
err: err.message,
links: {
['#drive_logs:' + currentJob.id]: 'View logs'
['#drive_logs:job-' + currentJob.id]: 'View logs'
},
});
}
Expand All @@ -383,7 +383,7 @@ export class JobManagerContainer extends Container {
type: 'git_commit:failed',
err: err.message,
links: {
['#drive_logs:' + currentJob.id]: 'View logs'
['#drive_logs:job-' + currentJob.id]: 'View logs'
},
});
}
Expand All @@ -394,7 +394,7 @@ export class JobManagerContainer extends Container {
type: 'git_push:failed',
err: err.message,
links: {
['#drive_logs:' + currentJob.id]: 'View logs'
['#drive_logs:job-' + currentJob.id]: 'View logs'
},
});
}
Expand All @@ -406,7 +406,7 @@ export class JobManagerContainer extends Container {
type: 'sync:failed',
err: err.message,
links: {
['#drive_logs:' + currentJob.id]: 'View logs'
['#drive_logs:job-' + currentJob.id]: 'View logs'
},
payload: 'all'
});
Expand Down Expand Up @@ -658,7 +658,10 @@ export class JobManagerContainer extends Container {
for (const path in filePaths.filter(path => path.endsWith('.md'))) {
const assetsPath = path.substring(0, path.length - 3) + '.assets';
if (await transformedFileSystem.exists(assetsPath)) {
fileAssetsPaths.push(assetsPath);
const files = await transformedFileSystem.list(assetsPath);
for (const file of files) {
fileAssetsPaths.push(file);
}
}
}
const removeFileAssetsPaths = [];
Expand All @@ -669,7 +672,10 @@ export class JobManagerContainer extends Container {
if (!await transformedFileSystem.exists(fileToRemove)) {
continue;
}
removeFileAssetsPaths.push(fileToRemove);
const files = await transformedFileSystem.list(fileToRemove);
for (const file of files) {
removeFileAssetsPaths.push(file);
}
}

filePaths.push(...fileAssetsPaths);
Expand Down Expand Up @@ -802,7 +808,7 @@ export class JobManagerContainer extends Container {
type: 'transform:failed',
err: err.message,
links: {
['#drive_logs:' + currentJob.id]: 'View logs'
['#drive_logs:job-' + currentJob.id]: 'View logs'
},
payload: currentJob.payload || 'all'
});
Expand All @@ -824,7 +830,7 @@ export class JobManagerContainer extends Container {
type: 'run_action:failed',
err: err.message,
links: {
['#drive_logs:' + currentJob.id]: 'View logs'
['#drive_logs:job-' + currentJob.id]: 'View logs'
}
});
throw err;
Expand Down Expand Up @@ -857,7 +863,7 @@ export class JobManagerContainer extends Container {
type: 'git_pull:failed',
err: err.message,
links: {
['#drive_logs:' + currentJob.id]: 'View logs'
['#drive_logs:job-' + currentJob.id]: 'View logs'
},
});
throw err;
Expand Down
6 changes: 5 additions & 1 deletion src/containers/server/ServerContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
getAuth,
authenticateOptionally,
validateGetAuthState,
handleDriveUiInstall, handleShare, handlePopupClose
handleDriveUiInstall, handleShare, handlePopupClose, redirError
} from './auth';
import {filterParams} from '../../google/driveFetch';
import {SearchController} from './routes/SearchController';
Expand Down Expand Up @@ -439,6 +439,10 @@ export class ServerContainer extends Container {
throw new Error('No DriveId');
}

if (!req.user?.google_access_token) {
throw redirError(req, 'Not authenticated');
}

const googleDriveService = new GoogleDriveService(this.logger, null);
const drive = await googleDriveService.getDrive(req.user.google_access_token, driveId);

Expand Down
19 changes: 18 additions & 1 deletion src/containers/server/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,23 @@ export async function handlePopupClose(req: Request, res: Response, next) {
}
}

function sanitizeRedirect(redirectTo: string) {
if ((redirectTo || '').startsWith('/gdocs/')) {
const [folderId, fileId] = redirectTo.substring('/gdocs/'.length).split('/');
if (folderId.match(/^[A-Z0-9_-]+$/ig) && fileId.match(/^[A-Z0-9_-]+$/ig)) {
return `/gdocs/${folderId}/${fileId}`;
}
}

const folderId = urlToFolderId(redirectTo);

if (!folderId) {
return '';
}

return `/drive/${folderId}`;
}

export async function getAuth(req, res: Response, next) {
try {
const hostname = req.header('host');
Expand Down Expand Up @@ -206,7 +223,7 @@ export async function getAuth(req, res: Response, next) {
err.showHtml = true;
throw err;
}
const redirectTo = urlToFolderId(state.get('redirectTo'));
const redirectTo = sanitizeRedirect(state.get('redirectTo'));

const authClient = new UserAuthClient(process.env.GOOGLE_AUTH_CLIENT_ID, process.env.GOOGLE_AUTH_CLIENT_SECRET);
await authClient.authorizeResponseCode(req.query.code, `${serverUrl}/auth`);
Expand Down
5 changes: 5 additions & 0 deletions src/containers/server/routes/DriveController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {googleMimeToExt} from '../../transform/TaskLocalFileTransform';
import {Container} from '../../../ContainerEngine';
import {GoogleTreeProcessor} from '../../google_folder/GoogleTreeProcessor';
import {getContentFileService} from '../../transform/utils';
import {redirError} from '../auth';

export class DriveController extends Controller {
constructor(subPath: string,
Expand All @@ -21,6 +22,10 @@ export class DriveController extends Controller {

@RouteGet('/')
async getDrives(@RouteParamUser() user) {
if (!user?.google_access_token) {
throw redirError(this.req, 'Not authenticated');
}

const folders = await this.folderRegistryContainer.getFolders();

const googleDriveService = new GoogleDriveService(this.logger, null);
Expand Down
5 changes: 5 additions & 0 deletions src/containers/server/routes/GoogleDriveController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export class GoogleDriveController extends Controller {
@RouteResponse('stream')
@RouteErrorHandler(new ShareErrorHandler())
async getDocs(@RouteParamPath('driveId') driveId: string, @RouteParamPath('fileId') fileId: string, @RouteParamUser() user) {
if (!user?.google_access_token) {
throw redirError(this.req, 'Not authenticated');
}

const googleFileSystem = await this.filesService.getSubFileService(driveId, '/');
const userConfigService = new UserConfigService(googleFileSystem);
await userConfigService.load();
Expand Down Expand Up @@ -145,6 +149,7 @@ export class GoogleDriveController extends Controller {
if (change.state.isDeleted) {
treeItem['status'] = 'D';
}
this.res.setHeader('wgd-git-attachments', String(change.attachments) || '0');
}
this.res.setHeader('wgd-git-status', treeItem['status'] || '');

Expand Down
6 changes: 4 additions & 2 deletions src/git/GitScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface GitChange {
isModified: boolean;
isDeleted: boolean;
};
attachments?: number;
}

interface SshParams {
Expand Down Expand Up @@ -49,7 +50,7 @@ export class GitScanner {

try {
await new Promise((resolve, reject) => {
exec(command, { cwd: this.rootPath, env: opts.env }, (error, stdoutResult, stderrResult) => {
exec(command, { cwd: this.rootPath, env: opts.env, maxBuffer: 1024 * 1024 }, (error, stdoutResult, stderrResult) => {
stdout = stdoutResult;
stderr = stderrResult;
if (error) {
Expand Down Expand Up @@ -87,13 +88,14 @@ export class GitScanner {
}

async changes(): Promise<GitChange[]> {
const retVal = {};
const retVal: { [path: string]: GitChange & { cnt: number } } = {};

const skipOthers = false;

function addEntry(path, state, attachments = 0) {
if (!retVal[path]) {
retVal[path] = {
cnt: 0,
path,
state: {
isNew: false,
Expand Down

0 comments on commit 81f7dd6

Please sign in to comment.