Skip to content

Commit

Permalink
Hot-update: cleanup, format
Browse files Browse the repository at this point in the history
- Remove some unnecessary print statements
- Clean up styling on navbar buttons
- Change user menu to user framer-motion
  • Loading branch information
printer83mph committed Apr 30, 2024
1 parent 5319c74 commit a9d6a2c
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 119 deletions.
1 change: 0 additions & 1 deletion backend/util/crud/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def read_users(db: Session, query: str | None = None, offset: int = 0):

# Create User
def create_user(db: Session, user: UserCreate):
print("troll")
hashed_password = bcrypt.hashpw(user.password.encode("utf-8"), bcrypt.gensalt())

db_user = User(
Expand Down
148 changes: 78 additions & 70 deletions frontend/src/main/lib/local-assets.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import archiver from 'archiver';
import { app, shell } from 'electron';
import extract from 'extract-zip';
import { hashElement } from 'folder-hash';
import { createWriteStream } from 'fs';
import { existsSync, copyFile } from 'node:fs';
import { copyFile, existsSync } from 'node:fs';
import fsPromises from 'node:fs/promises';
import path from 'node:path';
import { hashElement } from 'folder-hash';
import process from 'process';
import fs from 'fs';

import { DownloadedEntry, Version } from '../../types/ipc';
import { getAuthToken } from './authentication';
Expand Down Expand Up @@ -53,31 +52,31 @@ function setDownloadedVersion(
store.set('downloadedAssetVersions', newDownloads);
}

export async function getFolderHash(filePath: string): Promise<string>{
export async function getFolderHash(filePath: string): Promise<string> {
return hashElement(filePath)
.then(hash => {
return hash['hash'].toString()
})
.catch(error => {
console.error('hashing failed:', error);
});
.then((hash) => {
return hash['hash'].toString();
})
.catch((error) => {
console.error('hashing failed:', error);
});
}

export async function ifFilesChanged(asset_id: string): Promise<boolean> {
// compare current with saved hash
const downloads = await getDownloadedVersions()
const saved_asset = downloads.find((a) => asset_id === a.asset_id)
// compare current with saved hash
const downloads = await getDownloadedVersions();
const saved_asset = downloads.find((a) => asset_id === a.asset_id);
if (saved_asset === undefined) {
return true
return true;
}
const saved_hash = saved_asset.folderHash
const saved_hash = saved_asset.folderHash;

// what is the current hash
const folderName = saved_asset.folderName
const folderName = saved_asset.folderName;
const folderPath = path.join(getDownloadFolder(), folderName);
const current_hash = await getFolderHash(folderPath)
return (current_hash !== saved_hash)
const current_hash = await getFolderHash(folderPath);

return current_hash !== saved_hash;
}

/**
Expand All @@ -100,7 +99,7 @@ export async function createInitialVersion({
console.log('adding to store');

// hash new folder
const folderHash = await getFolderHash(folderPath)
const folderHash = await getFolderHash(folderPath);
setDownloadedVersion(asset_id, { semver: null, folderName, folderHash });
}

Expand Down Expand Up @@ -190,7 +189,7 @@ export async function commitChanges(asset_id: string, message: string, is_major:
}

// Update saved hash
const folderHash = await getFolderHash(sourceFolder)
const folderHash = await getFolderHash(sourceFolder);

// Update store with currently downloaded version
const { semver } = result.data as Version;
Expand Down Expand Up @@ -244,7 +243,7 @@ export async function downloadVersion({ asset_id, semver }: { asset_id: string;
// previously had semver in here but probably not necessary
// const folderName = `${asset_name}_${semver}_${asset_id.substring(0, 8)}/`;
const folderName = `${asset_name}_${asset_id.substring(0, 8)}/`;
const folderPath = path.join(getDownloadFolder(), folderName)
const folderPath = path.join(getDownloadFolder(), folderName);

// remove old copy of folder
await fsPromises.rm(path.join(getDownloadFolder(), folderName), { force: true, recursive: true });
Expand All @@ -253,7 +252,7 @@ export async function downloadVersion({ asset_id, semver }: { asset_id: string;
console.log('removing zip file...');
await fsPromises.rm(zipFilePath);

const folderHash = await getFolderHash(folderPath)
const folderHash = await getFolderHash(folderPath);
console.log('marking as stored!');
setDownloadedVersion(asset_id, { semver, folderName, folderHash });

Expand Down Expand Up @@ -281,10 +280,13 @@ export async function unsyncAsset(asset_id: string) {
}

function getCommandLine() {
switch (process.platform) {
case 'darwin' : return 'open ';
case 'win32' : return 'start ';
default : return 'xdg-open';
switch (process.platform) {
case 'darwin':
return 'open ';
case 'win32':
return 'start ';
default:
return 'xdg-open';
}
}

Expand All @@ -304,48 +306,52 @@ export async function openHoudini(asset_id: string) {
if (!process.env.HFS) return;
const houdiniCmd = path.join(process.env.HFS, '/bin/houdini');

const { spawn, exec } = require("child_process");
const { spawn, exec } = require('child_process');

// If there's an existing Houdini file, open it.
const destination = path.join(downloadsFullpath, `${assetName}.hipnc`);
if (existsSync(destination)) {
exec(getCommandLine() + destination);
console.log(`Launching the existing Houdini file for ${asset_id}...`);
}
}
// Otherwise, load asset in a new template.
else {
const existsUsdOld = existsSync(path.join(downloadsFullpath, 'root.usda'));
const existsUsdNew = existsSync(path.join(downloadsFullpath, `${assetName}.usda`));
const houdiniTemplate = (!existsUsdOld && !existsUsdNew) ? 'CreateNew.hipnc' : 'Update.hipnc';
const houdiniTemplate = !existsUsdOld && !existsUsdNew ? 'CreateNew.hipnc' : 'Update.hipnc';
const templateFullpath = path.join(process.cwd(), `${houdini_src}${houdiniTemplate}`);

// Copy template to asset's folder so we don't always edit on the same file
copyFile(templateFullpath, destination, (err) => {
if (err) throw err;
console.log(`${houdiniTemplate} was copied to ${destination}`);
});

const pythonScript = path.join(process.cwd(), `${houdini_src}/launchTemplate.py`);

// Launch houdini with a python session attached
const bat = spawn(houdiniCmd, [
destination, // Argument for cmd to carry out the specified file
pythonScript, // Path to your script
"-a", // First argument
assetName, // n-th argument
"-o",
downloadsFullpath,
"-n",
downloadsFullpath
], {
shell: true,
});

bat.stdout.on("data", (data) => {
const bat = spawn(
houdiniCmd,
[
destination, // Argument for cmd to carry out the specified file
pythonScript, // Path to your script
'-a', // First argument
assetName, // n-th argument
'-o',
downloadsFullpath,
'-n',
downloadsFullpath,
],
{
shell: true,
},
);

bat.stdout.on('data', (data) => {
console.log(data.toString());
});
bat.stderr.on("data", (err) => {

bat.stderr.on('data', (err) => {
console.log(err.toString());
});
}
Expand All @@ -366,40 +372,42 @@ export async function quietRenderHoudini(asset_id: string) {
if (!process.env.HFS) return;
const houdiniHython = path.join(process.env.HFS, '/bin/hython');

const { spawn } = require("child_process");
const { spawn } = require('child_process');

const pythonScript = path.join(process.cwd(), `${houdini_src}/quietRender.py`);

// locate the asset USD file based on different asset structures
const usdNewFullpath = path.join(downloadsFullpath, 'root.usda');
const usdOldFullpath = path.join(downloadsFullpath, `${assetName}.usda`);
let assetFullpath;
if (existsSync(usdOldFullpath)) {
assetFullpath = usdOldFullpath;
}
else if (existsSync(usdNewFullpath)) {
} else if (existsSync(usdNewFullpath)) {
assetFullpath = usdNewFullpath;
}
else {
console.log("No correct asset USD to render!");
} else {
console.log('No correct asset USD to render!');
return;
}

const bat = spawn(houdiniHython, [
pythonScript, // Argument for cmd to carry out the specified file
"-a", // First argument
assetFullpath, // n-th argument
"-o",
downloadsFullpath
], {
shell: true,
});

bat.stdout.on("data", (data) => {

const bat = spawn(
houdiniHython,
[
pythonScript, // Argument for cmd to carry out the specified file
'-a', // First argument
assetFullpath, // n-th argument
'-o',
downloadsFullpath,
],
{
shell: true,
},
);

bat.stdout.on('data', (data) => {
console.log(data.toString());
});
bat.stderr.on("data", (err) => {

bat.stderr.on('data', (err) => {
console.log(err.toString());
});
}
2 changes: 1 addition & 1 deletion frontend/src/main/message-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
// Types for these can be found in `src/types/ipc.d.ts`
const messageHandlers: MessageHandlers = {
'assets:list-downloaded': async () => {
// console.log('getting downloaded:', getStoredVersions());
return { ok: true, versions: getDownloadedVersions() };
},
'assets:download-asset': async (_, { asset_id }) => {
Expand All @@ -33,6 +32,7 @@ const messageHandlers: MessageHandlers = {
return { ok: true };
},
'assets:remove-download': async (_, { asset_id }) => {
console.log(`Unsyncing ${asset_id}`);
await unsyncAsset(asset_id);
return { ok: true };
},
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/renderer/src/components/forms/new-user-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default function NewUserForm({
// --------------------------------------------

const submitHandler = async (data: NewUserFormData) => {
// create profile pic uri
// create profile pic uri
let encoded_uri = '';

// check if picture file exists
Expand All @@ -65,8 +65,8 @@ export default function NewUserForm({
console.error('Error encoding profile image:', err);
return;
}
}
}

// Create the user
try {
const { error } = await fetchClient.POST('/api/v1/users/', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function ControlledInput({ inputName, inputs, setInputs }: ControlledInputProps)

return (
<label className="block">
<Label label={`By ${inputName}`} />
<Label label={inputName} />
<div className="relative w-full">
<input
type="text"
Expand Down
10 changes: 6 additions & 4 deletions frontend/src/renderer/src/components/layout/navbar-filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import ControlledKeywordsInput from '../input/filter-keywords-input';
import Label from '../input/label';

const NavbarFilter = () => {
const [dropdownVisible, setDropdownVisible] = useState(false); // State to control dropdown visibility
// State to control dropdown visibility
const [dropdownVisible, setDropdownVisible] = useState(false);

const { keywords, archived, setKeywords, setArchived } = useSearchParamsStore();
const { sort, setSort } = useSearchParamsStore();

// close on click outside
const ref = useRef<HTMLDivElement>(null!);
useOnClickOutside(ref, () => setDropdownVisible(false));

Expand All @@ -25,7 +27,7 @@ const NavbarFilter = () => {
<div
tabIndex={0}
role="button"
className="btn btn-outline flex items-center"
className="btn btn-ghost flex items-center"
onClick={() => setDropdownVisible((v) => !v)}
>
<CiFilter className="h-6 w-6" />
Expand Down Expand Up @@ -56,7 +58,7 @@ const NavbarFilter = () => {
{/* Keyword constraints */}
<li className="mb-4">
<ControlledKeywordsInput
inputName={'Keywords'}
inputName={'Require Keywords'}
inputs={keywords}
setInputs={setKeywords}
/>
Expand All @@ -77,7 +79,7 @@ const NavbarFilter = () => {
<li className="form-control">
<label className="label cursor-pointer">
<span
className={`label-text flex items-center gap-2 transition-colors ${archived ? 'text-warning' : ''}`}
className={`label-text -mx-3 -my-1 flex items-center gap-2 rounded-badge px-3 py-1 transition-colors ${archived ? 'bg-warning text-warning-content' : ''}`}
>
<MdArchive />
Show Archived
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/renderer/src/components/layout/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const Navbar = () => {
{/* Center Group */}
<div className="flex flex-grow items-center justify-center gap-x-4 ">
{/* New Asset Button */}
<Link className="btn btn-outline" to={loggedIn ? '/new-asset' : '/user-login'}>
<Link className="btn btn-ghost" to={loggedIn ? '/new-asset' : '/user-login'}>
{loggedIn ? (
<>
<MdCreate /> New Asset
Expand Down
Loading

0 comments on commit a9d6a2c

Please sign in to comment.