-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Web extension resources return incorrect MIME type
Use [Content_Types].xml to set FileResource contentType Add test case for default content type: application/octet-stream Add migration to set FileResource.contentType Set contentType for RESOURCE type Prepend dot ('.') if extension doesn't start with a dot.
- Loading branch information
amvanbaren
committed
Dec 16, 2022
1 parent
f061c72
commit 9f36399
Showing
39 changed files
with
886 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
server/src/main/java/org/eclipse/openvsx/migration/SetContentTypeJobRequestHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** ****************************************************************************** | ||
* Copyright (c) 2022 Precies. Software Ltd and others | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* ****************************************************************************** */ | ||
package org.eclipse.openvsx.migration; | ||
|
||
import org.eclipse.openvsx.ExtensionProcessor; | ||
import org.eclipse.openvsx.entities.ExtensionVersion; | ||
import org.eclipse.openvsx.entities.FileResource; | ||
import org.jobrunr.jobs.annotations.Job; | ||
import org.jobrunr.jobs.context.JobRunrDashboardLogger; | ||
import org.jobrunr.jobs.lambdas.JobRequestHandler; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.function.Consumer; | ||
|
||
@Component | ||
public class SetContentTypeJobRequestHandler implements JobRequestHandler<MigrationJobRequest> { | ||
|
||
protected final Logger logger = new JobRunrDashboardLogger(LoggerFactory.getLogger(ExtractResourcesJobRequestHandler.class)); | ||
|
||
@Autowired | ||
MigrationService migrations; | ||
|
||
@Autowired | ||
SetContentTypeJobService service; | ||
|
||
@Override | ||
@Job(name = "Set content type for published file resources", retries = 3) | ||
public void run(MigrationJobRequest jobRequest) throws Exception { | ||
var extVersion = migrations.find(jobRequest, ExtensionVersion.class); | ||
logger.info("Set content type for: {}.{}-{}@{}", extVersion.getExtension().getNamespace().getName(), extVersion.getExtension().getName(), extVersion.getVersion(), extVersion.getTargetPlatform()); | ||
|
||
var entry = migrations.getDownload(extVersion); | ||
var extensionFile = migrations.getExtensionFile(entry); | ||
try (var processor = new ExtensionProcessor(extensionFile)) { | ||
Consumer<FileResource> consumer = resource -> { | ||
service.setContentType(extVersion, resource); | ||
migrations.deleteResource(resource); | ||
migrations.uploadResource(resource); | ||
}; | ||
|
||
processor.getFileResources(extVersion).forEach(consumer); | ||
processor.processEachResource(extVersion, consumer); | ||
} | ||
} | ||
} |
Oops, something went wrong.