bug fix in EventGaleryController, diffrent name of link in database and real link for getting image

master
dizda13 2017-06-08 22:24:00 +02:00
parent 12958470b7
commit f0be249b0f
5 changed files with 44 additions and 23 deletions

View File

@ -0,0 +1,29 @@
package ba.steleks;
/**
* Created by admin on 06/05/2017.
*/
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
@Configuration
public class CrossOriginConfig {
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.addAllowedMethod("OPTIONS");
config.addAllowedMethod("GET");
config.addAllowedMethod("POST");
config.addAllowedMethod("PUT");
config.addAllowedMethod("DELETE");
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
}

View File

@ -41,7 +41,7 @@ public class EventGalleryController {
@ResponseBody @ResponseBody
public ResponseEntity<Resource> serveFile(@PathVariable String filename) { public ResponseEntity<Resource> serveFile(@PathVariable String filename) {
Resource file = storageService.loadAsResource("mediaEvent/"+filename); Resource file = storageService.loadAsResource("eventPictures/"+filename);
return ResponseEntity return ResponseEntity
.ok() .ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\""+file.getFilename()+"\"") .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\""+file.getFilename()+"\"")
@ -54,14 +54,20 @@ public class EventGalleryController {
String mediaServiceBase = discoveryClient.getServiceUrl(Service.EVENTS); String mediaServiceBase = discoveryClient.getServiceUrl(Service.EVENTS);
System.out.println(mediaServiceBase);
String[] names = file.getOriginalFilename().split("\\."); String[] names = file.getOriginalFilename().split("\\.");
String dest = String.valueOf("mediaEvent/" + mediaId + "_" + new Date().getTime()) + "." + names[names.length - 1]; String dest = String.valueOf("eventPictures/" + mediaId + "_" + new Date().getTime()) + "." + names[names.length - 1];
storageService.store(file, dest); storageService.store(file, dest);
redirectAttributes.addFlashAttribute("message", redirectAttributes.addFlashAttribute("message",
"You successfully uploaded " + file.getOriginalFilename() + "!"); "You successfully uploaded " + file.getOriginalFilename() + "!");
System.out.println(dest);
Media media = repository.findOne(mediaId); Media media = repository.findOne(mediaId);
if(media==null){
media= new Media();
media.setContentUrl(mediaServiceBase +"/" + dest);
media.setCreatedById(0);
repository.save(media);
}else
media.setContentUrl(mediaServiceBase +"/" + dest); media.setContentUrl(mediaServiceBase +"/" + dest);
repository.save(media); repository.save(media);

View File

@ -14,24 +14,6 @@ import org.springframework.web.filter.CorsFilter;
@SpringBootApplication @SpringBootApplication
public class SteleksProxyApplication { public class SteleksProxyApplication {
@Bean
public CorsFilter corsFilter() {
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
final CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.addAllowedMethod("OPTIONS");
config.addAllowedMethod("HEAD");
config.addAllowedMethod("GET");
config.addAllowedMethod("PUT");
config.addAllowedMethod("POST");
config.addAllowedMethod("DELETE");
config.addAllowedMethod("PATCH");
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(SteleksProxyApplication.class, args); SpringApplication.run(SteleksProxyApplication.class, args);
} }

View File

@ -40,6 +40,7 @@ dependencies {
compile('org.springframework.cloud:spring-cloud-starter-eureka') compile('org.springframework.cloud:spring-cloud-starter-eureka')
compile('io.jsonwebtoken:jjwt:0.7.0') compile('io.jsonwebtoken:jjwt:0.7.0')
compile project(':common') compile project(':common')
compile('org.springframework.security:spring-security-jwt')
testCompile('org.springframework.cloud:spring-cloud-starter-eureka-server') testCompile('org.springframework.cloud:spring-cloud-starter-eureka-server')
} }

View File

@ -10,6 +10,7 @@ import ba.steleks.security.token.TokenStore;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -27,6 +28,7 @@ public class AuthenticationController {
private TokenStore tokenStore; private TokenStore tokenStore;
@Autowired @Autowired
public AuthenticationController(UsersJpaRepository usersJpaRepository, PasswordEncoder passwordEncoder, TokenStore tokenStore) { public AuthenticationController(UsersJpaRepository usersJpaRepository, PasswordEncoder passwordEncoder, TokenStore tokenStore) {
this.usersJpaRepository = usersJpaRepository; this.usersJpaRepository = usersJpaRepository;
this.passwordEncoder = passwordEncoder; this.passwordEncoder = passwordEncoder;
@ -59,6 +61,7 @@ public class AuthenticationController {
throw new CustomHttpStatusException(HttpStatus.UNAUTHORIZED, throw new CustomHttpStatusException(HttpStatus.UNAUTHORIZED,
"Invalid password!"); "Invalid password!");
} }
} }
@RequestMapping(path = "/accesstoken/{token}", method = RequestMethod.DELETE) @RequestMapping(path = "/accesstoken/{token}", method = RequestMethod.DELETE)