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 d6c8fd9
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 7 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
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">
<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" 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
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
4 changes: 3 additions & 1 deletion 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 @@ -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 d6c8fd9

Please sign in to comment.