Skip to content

Commit

Permalink
BUGFIX: Move resource logic to server
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Jan 23, 2024
1 parent eb3765b commit 16df4da
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
13 changes: 13 additions & 0 deletions Classes/Controller/BackendServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Neos\Flow\Persistence\Exception\IllegalObjectTypeException;
use Neos\Flow\Persistence\PersistenceManagerInterface;
use Neos\Flow\Property\PropertyMapper;
use Neos\Flow\ResourceManagement\ResourceManager;
use Neos\Neos\Domain\Service\ContentContextFactory;
use Neos\Neos\Domain\Service\ContentDimensionPresetSourceInterface;
use Neos\Neos\Service\PublishingService;
Expand Down Expand Up @@ -157,6 +158,12 @@ class BackendServiceController extends ActionController
*/
protected $nodeUriPathSegmentGenerator;

/**
* @Flow\Inject
* @var ResourceManager
*/
protected $resourceManager;

/**
* Set the controller context on the feedback collection after the controller
* has been initialized
Expand Down Expand Up @@ -563,4 +570,10 @@ public function generateUriPathSegmentAction(NodeInterface $contextNode, string
$slug = $this->nodeUriPathSegmentGenerator->generateUriPathSegment($contextNode, $text);
$this->view->assign('value', $slug);
}

public function redirectToResourceUriAction(string $resourcePath): void
{
$target = $this->resourceManager->getPublicPackageResourceUriByPath($resourcePath);
$this->redirectToUri($target, 0, 301);
}
}
8 changes: 8 additions & 0 deletions Configuration/Routes.Service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,11 @@
'@controller': 'BackendService'
'@action': 'generateUriPathSegment'
httpMethods: ['POST']

-
name: 'Redirect to resource uri'
uriPattern: 'redirect-resource-uri'
defaults:
'@controller': 'BackendService'
'@action': 'redirectToResourceUri'
httpMethods: ['GET']
3 changes: 3 additions & 0 deletions Resources/Private/Fusion/Backend/Root.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ backend = Neos.Fusion:Template {
generateUriPathSegment = Neos.Fusion:UriBuilder {
action = 'generateUriPathSegment'
}
redirectToResourceUri = Neos.Fusion:UriBuilder {
action = 'redirectToResourceUri'
}
getWorkspaceInfo = Neos.Fusion:UriBuilder {
action = 'getWorkspaceInfo'
}
Expand Down
1 change: 1 addition & 0 deletions packages/neos-ui-backend-connector/src/Endpoints/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface Routes {
generateUriPathSegment: string;
getWorkspaceInfo: string;
getAdditionalNodeMetadata: string;
redirectToResourceUri: string;
};
};
core: {
Expand Down
6 changes: 5 additions & 1 deletion packages/neos-ui/src/Containers/Root.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ class Root extends PureComponent {

const containerRegistry = globalRegistry.get('containers');
const App = containerRegistry.get('App');
const createFromResourcePath = (path) => '/_Resources/Static/Packages/' + path.substr(11);
const createFromResourcePath = (resourcePath) => {
const redirectToResourceUri = new URL(routes.ui.service.redirectToResourceUri);
redirectToResourceUri.searchParams.set('resourcePath', resourcePath);
return redirectToResourceUri.toString();
};

return (
<ErrorBoundary i18nRegistry={globalRegistry.get('i18n')}>
Expand Down
22 changes: 18 additions & 4 deletions packages/react-ui-components/src/Icon/resourceIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,30 @@ class ResourceIcon extends PureComponent<ResourceIconProps> {
public render(): JSX.Element | null {
const {padded, theme, label, icon, className, color, size} = this.props;

if (!icon?.startsWith('resource://')) {
return null;
}

Check failure on line 28 in packages/react-ui-components/src/Icon/resourceIcon.tsx

View workflow job for this annotation

GitHub Actions / Code style

More than 1 blank line not allowed

if (!this.context) {
console.error('ResourceIconContext missing! Cannot resolve uri: ', icon);
return null;
}

const iconResourcePath = this.context.createFromResourcePath(icon);
const regex = /^resource:\/\/([^\\/]+)\/(.*)/;

const matches = icon?.match(regex);

if (!matches) {
return null;
}
const [_, packageName, rawPath] = matches;

Check failure on line 42 in packages/react-ui-components/src/Icon/resourceIcon.tsx

View workflow job for this annotation

GitHub Actions / Code style

'_' is assigned a value but never used

let publicPath = rawPath;
if (!rawPath.startsWith('Public/')) {
publicPath = `Public/${rawPath}`;
}

const resourcePath = `resource://${packageName}/${publicPath}`;

const iconResourcePath = this.context.createFromResourcePath(resourcePath);
const classNames = mergeClassNames(
theme!.icon,
className,
Expand Down

0 comments on commit 16df4da

Please sign in to comment.