Adaptations for legacy database importation.
This commit is contained in:
@@ -7,7 +7,7 @@ import org.springframework.stereotype.Component;
|
|||||||
@Component
|
@Component
|
||||||
public class KeyGenerator {
|
public class KeyGenerator {
|
||||||
private static final String ALLOWED_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
private static final String ALLOWED_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||||
private static final int KEY_LENGTH = 10;
|
private static final int KEY_LENGTH = 14;
|
||||||
|
|
||||||
public String generateKey() {
|
public String generateKey() {
|
||||||
SecureRandom random = new SecureRandom();
|
SecureRandom random = new SecureRandom();
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ public class MultipartFileConverter {
|
|||||||
try {
|
try {
|
||||||
ALLOWED_MIME_TYPES = List.of(
|
ALLOWED_MIME_TYPES = List.of(
|
||||||
mimeTypes.forName("image/png"),
|
mimeTypes.forName("image/png"),
|
||||||
mimeTypes.forName("image/jpeg")
|
mimeTypes.forName("image/jpeg"),
|
||||||
|
mimeTypes.forName("image/svg+xml")
|
||||||
);
|
);
|
||||||
} catch (MimeTypeException exception) {
|
} catch (MimeTypeException exception) {
|
||||||
throw new RuntimeException("An error occurred while loading allowed mime types.", exception);
|
throw new RuntimeException("An error occurred while loading allowed mime types.", exception);
|
||||||
@@ -48,16 +49,15 @@ public class MultipartFileConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String buildPicturePath(MultipartFile fileContent) {
|
private String buildPicturePath(MultipartFile fileContent) {
|
||||||
MimeType fileContentType = extractMimeType(fileContent);
|
checkMimeTypeIsAllowed(fileContent);
|
||||||
return String.format(
|
return String.format(
|
||||||
"%s/%s%s",
|
"%s/%s",
|
||||||
tempPicturesFolderPath,
|
tempPicturesFolderPath,
|
||||||
UUID.randomUUID(),
|
UUID.randomUUID()
|
||||||
fileContentType.getExtension()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MimeType extractMimeType(MultipartFile fileContent) {
|
private void checkMimeTypeIsAllowed(MultipartFile fileContent) {
|
||||||
MimeType result = null;
|
MimeType result = null;
|
||||||
try {
|
try {
|
||||||
result = MimeTypes.getDefaultMimeTypes()
|
result = MimeTypes.getDefaultMimeTypes()
|
||||||
@@ -69,8 +69,6 @@ public class MultipartFileConverter {
|
|||||||
if (isNull(result) || !isAllowedMimeType(result)) {
|
if (isNull(result) || !isAllowedMimeType(result)) {
|
||||||
throw new PictureUploadException("Unable to upload the picture because its format is incorrect.");
|
throw new PictureUploadException("Unable to upload the picture because its format is incorrect.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isAllowedMimeType(MimeType mimeType) {
|
private boolean isAllowedMimeType(MimeType mimeType) {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ CREATE INDEX user_photo_id_idx ON "user" (photo_id);
|
|||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS publication (
|
CREATE TABLE IF NOT EXISTS publication (
|
||||||
id UUID NOT NULL,
|
id UUID NOT NULL,
|
||||||
key VARCHAR(10) NOT NULL,
|
key VARCHAR(14) NOT NULL,
|
||||||
title VARCHAR NOT NULL,
|
title VARCHAR NOT NULL,
|
||||||
text VARCHAR NOT NULL,
|
text VARCHAR NOT NULL,
|
||||||
description VARCHAR NOT NULL,
|
description VARCHAR NOT NULL,
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ application:
|
|||||||
path: /Users/florian_thierry/Documents/Developpement/codiki-hexa/pictures-folder/
|
path: /Users/florian_thierry/Documents/Developpement/codiki-hexa/pictures-folder/
|
||||||
temp-path : /Users/florian_thierry/Documents/Developpement/codiki-hexa/pictures-folder/temp/
|
temp-path : /Users/florian_thierry/Documents/Developpement/codiki-hexa/pictures-folder/temp/
|
||||||
|
|
||||||
|
server:
|
||||||
|
port: 8987
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
jpa:
|
jpa:
|
||||||
show-sql: true
|
show-sql: true
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
vars {
|
vars {
|
||||||
url: http://localhost:8080
|
url: http://localhost:8987
|
||||||
publicationId: ec76602f-5501-4091-868e-b471611e63de
|
publicationId: ec76602f-5501-4091-868e-b471611e63de
|
||||||
bearerToken: eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI1YWQ0NjJiOC04ZjllLTRhMjYtYmI4Ni1jNzRmZWY1ZDExYjYiLCJleHAiOjE3MTA4Mzc2ODQsInBzZXVkbyI6IlN0YW5kYXJkIHVzZXIiLCJlbWFpbCI6InN0YW5kYXJkLnVzZXJAY29kaWtpLm9yZyIsInJvbGVzIjoiU1RBTkRBUkQifQ.2HggC3T_4I14IpW02DZJiYfgYwc074kU8Y4AmuGf1mZzv0U8OUxpAw_xEhnKtn8NcaCozz_2vFv4o_CaBqS8Ag
|
bearerToken: eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI1YWQ0NjJiOC04ZjllLTRhMjYtYmI4Ni1jNzRmZWY1ZDExYjYiLCJleHAiOjE3MTA4Mzc2ODQsInBzZXVkbyI6IlN0YW5kYXJkIHVzZXIiLCJlbWFpbCI6InN0YW5kYXJkLnVzZXJAY29kaWtpLm9yZyIsInJvbGVzIjoiU1RBTkRBUkQifQ.2HggC3T_4I14IpW02DZJiYfgYwc074kU8Y4AmuGf1mZzv0U8OUxpAw_xEhnKtn8NcaCozz_2vFv4o_CaBqS8Ag
|
||||||
categoryId: 172fa901-3f4b-4540-92f3-1c15820e8ec9
|
categoryId: 172fa901-3f4b-4540-92f3-1c15820e8ec9
|
||||||
|
|||||||
Reference in New Issue
Block a user